[React] Persist Form Data in React and Formik with formik-persist
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的更多相关文章
- [React] Controlling Form Values with React
In this lesson we'll talk about controlling the value for inputs, textareas, and select elements. We ...
- react antd form多组表单数据处理
import React from 'react'; import {Form, InputNumber, Input, DatePicker, Button, Select, Icon} from ...
- 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 ...
- (转)2019年 React 新手学习指南 – 从 React 学习线路图说开去
原文:https://www.html.cn/archives/10111 注:本文根据 React 开发者学习线路图(2018) 结构编写了很多新手如何学习 React 的建议.2019 年有标题党 ...
- react 后台(一) react + redux + react-route + webpack+ axios + antd + less
create-react-app 项目名称(项目失败,ant 的样式出不来) 项目技术栈 react + redux + react-route + webpack+ axios + less + a ...
- form data和request payload的区别
HTML <form> 标签的 enctype 属性 在下面的例子中,表单数据会在未编码的情况下进行发送: <form action="form_action.asp&qu ...
- AngularJS $http配置为form data 提交
AngularJS $http配置为form data 提交 $scope.formData = {}; $http({ method: 'POST', url: '/user/', // pass ...
- Web 前沿——HTML5 Form Data 对象的使用
XMLHttpRequest Level 2 添加了一个新的接口——FormData.利用 FormData 对象,我们可以通过 JavaScript 用一些键值对来模拟一系列表单控件,我们还可以使用 ...
- React Canvas:高性能渲染 React 组
React Canvas 提供了使用 Canvas 渲染移动 Web App 界面的能力,替代传统的 DOM 渲染,具有更接近 Native App 的使用体验.React Canvas 提供了一组标 ...
随机推荐
- django 12天(跨域,文件上传,下载,cookie,session)
django 12天(跨域,文件上传,下载) 跨域 什么是跨域 1.协议不同 2.端口不同 3.主机不同 如何解决跨域 1.安装django-cors-headers模块 2.在settings.py ...
- shell-note-1-基础篇
1. Shell is a program written in C. It provides an interface for users to access to the service of o ...
- centos中python2替换为python3,并解决yum出错
这里采用安装python3.6版本. 安装python3.6可能使用的依赖 yum install openssl-devel bzip2-devel expat-devel gdbm-devel r ...
- Debian 9 更新 sourrce.list(163源)
Debian 9 更新 sourrce.list(163源) 需求说明: 更新apt-get源 kyeup@kyeup-nas:~$ lsb_release -a No LSB modules are ...
- windows liver writer下载地址
wlsetup-all.exe 链接:http://pan.baidu.com/s/1bo9pm7X 密码:zchb wlsetup-all简体版.exe 链接:http://pan.baidu.co ...
- BNUOJ 3580 Oulipo
Oulipo Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on PKU. Original ID: 3 ...
- linux open()文件操作
python程序中经常用到的读文件: f = open("___", 'r') for line in f:#这里每次读取文件的一行,line为字符串,串尾包括了'\n'!!! ...
- spring配置mybatis3
mybatis官方网站:http://www.mybatis.org/mybatis-3/zh/configuration.html <!--第一步:加载配置数据库相关参数--> < ...
- [UOJ#219][BZOJ4650][Noi2016]优秀的拆分
[UOJ#219][BZOJ4650][Noi2016]优秀的拆分 试题描述 如果一个字符串可以被拆分为 AABBAABB 的形式,其中 A 和 B 是任意非空字符串,则我们称该字符串的这种拆分是优秀 ...
- bzoj1064【Noi2008】假面舞会
题意:http://www.lydsy.com/JudgeOnline/problem.php?id=1064 给一个有向图染色,每个点的后继必须相同,问至少&至多有多少种染色方案 sol: ...