It can be incredibly frustrating to spend a few minutes filling out a form only to accidentally lose all of your progress by the browser closer, the page refreshing, or many other terrible scenarios. formik-persist saves you from that fate by providing a Persist component which you can drop inside of any Formik Form to save the state of the form into localStorage. This lesson walks you through creating the Form and using the Formik Persist component.

import React, { Component } from "react"
import "./App.css"
import { Formik, Form, Field } from "formik"
import { Persist } from "formik-persist" class App extends Component {
state = {
firstName: "",
lastName: ""
} render() {
return (
<>
<Formik onSubmit={values => this.setState(values)}>
{props => (
<Form style={{ display: "flex", flexDirection: "column" }}>
<label htmlFor="firstName">First Name</label>
<Field id="firstName" name="firstName" />
<label htmlFor="lastName">Last Name</label>
<Field id="lastName" name="lastName" />
<button type="submit">Submit</button>
<Persist name="person-form" />
</Form>
)}
</Formik>
{JSON.stringify(this.state)}
</>
)
}
} export default App

[React] Persist Form Data in React and Formik with formik-persist的更多相关文章

  1. [React] Controlling Form Values with React

    In this lesson we'll talk about controlling the value for inputs, textareas, and select elements. We ...

  2. react antd form多组表单数据处理

    import React from 'react'; import {Form, InputNumber, Input, DatePicker, Button, Select, Icon} from ...

  3. How to fetch data with React Hooks

    Where can I make API call with hooks in react? Async useEffect is pretty much unreadable How to fetc ...

  4. (转)2019年 React 新手学习指南 – 从 React 学习线路图说开去

    原文:https://www.html.cn/archives/10111 注:本文根据 React 开发者学习线路图(2018) 结构编写了很多新手如何学习 React 的建议.2019 年有标题党 ...

  5. react 后台(一) react + redux + react-route + webpack+ axios + antd + less

    create-react-app 项目名称(项目失败,ant 的样式出不来) 项目技术栈 react + redux + react-route + webpack+ axios + less + a ...

  6. form data和request payload的区别

    HTML <form> 标签的 enctype 属性 在下面的例子中,表单数据会在未编码的情况下进行发送: <form action="form_action.asp&qu ...

  7. AngularJS $http配置为form data 提交

    AngularJS $http配置为form data 提交 $scope.formData = {}; $http({ method: 'POST', url: '/user/', // pass ...

  8. Web 前沿——HTML5 Form Data 对象的使用

    XMLHttpRequest Level 2 添加了一个新的接口——FormData.利用 FormData 对象,我们可以通过 JavaScript 用一些键值对来模拟一系列表单控件,我们还可以使用 ...

  9. React Canvas:高性能渲染 React 组

    React Canvas 提供了使用 Canvas 渲染移动 Web App 界面的能力,替代传统的 DOM 渲染,具有更接近 Native App 的使用体验.React Canvas 提供了一组标 ...

随机推荐

  1. 【Linux】VirtualBox虚拟网络配置

    Host OS : Windows 10 Guest OS : CentOS 6.8 VirtualBox:5.1.18 网络连接方式: NAT 1.CentOS中使用DHCP [root@gouka ...

  2. perl学习之I/O基础

    1.从标准输入进行输入<STDIN> 2.从钻石操作符进行输入<> 3.参数调用@ARGV 4.向标准输出进行输出 5.用printf进行格式化输出 1.<STDIN&g ...

  3. 【php】Windows PHP及xdebug安装 安装

    php version 7.0 redis 下载地址 https://pecl.php.net/package/redis 7.0版本的redis不再依赖php_igbinary.dll扩展,可以独立 ...

  4. 3,bool值之间的转换,和str的各个功能属性。

    bool值之间的转换 and 空字符串即为False   字符串内有内容即为True. a = 11 c = str(a) #int转换成str print(type(c)) a = ' b = in ...

  5. android 之 菜单

    android的菜单主要分三类:选项菜单(Options Menu).上下文菜单(Context Menu).子菜单(Submenu). 1 选项菜单和子菜单 一个Menu对象代表一个菜单,Menu中 ...

  6. android 之 Intent、broadcast

    Intent的功能有: 在mainActivity中为按钮1添加监听事件: listener1 = new OnClickListener() { @Override    public void o ...

  7. World Finals 2017

    Need for Speed   Sheila is a student and she drives a typical student car: it is old, slow, rusty, a ...

  8. 九度oj 题目1207:质因数的个数

    题目描述: 求正整数N(N>1)的质因数的个数. 相同的质因数需要重复计算.如120=2*2*2*3*5,共有5个质因数. 输入: 可能有多组测试数据,每组测试数据的输入是一个正整数N,(1&l ...

  9. POJ 2643 Election

    Election Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3558   Accepted: 1692 Descript ...

  10. BZOJ 2829 信用卡凸包 ——计算几何

    凸包裸题 #include <map> #include <cmath> #include <queue> #include <cstdio> #inc ...