[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 提供了一组标 ...
随机推荐
- python上的数据库sqlite3——插入多行数据
学校课程上的一个知识点,一个简单的课后习题:一劳永逸实现多行数据的插入(应该是这个意思,老师也没讲清楚).直接上代码了没啥好讲的,我感觉这个思路好捞. import sqlite3 con = sql ...
- python--subprocess,粘包现象与解决办法,缓冲区
一. subprocess 的简单用法 import subprocess sub_obj = subprocess.Popen( 'dir', #系统指令 shell=True, #固定方法 std ...
- ajax动态刷新下拉框
动态post,避免直接给页面传输大量数据 /** * ajax通过商品刷新供应商 * by_kangyx * @throws IOException */ @RequestMapping(params ...
- 引用类型(JavaScript第5章)
引用类型的值(对象)是引用类型的一个实例.在ECMScript中,引用类型是一种数据结构,用于将数据和功能组织在一起. 一.Object类型 创建Object实例的方式有两种.第一种是使用new操作符 ...
- 2011 Michigan Invitational Programming Contest
Crossings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100463 Description ...
- LINUX远程强制重启/proc/sys/kernel/sysrq /proc/sysrq-trigger
1. # echo 1 > /proc/sys/kernel/sysrq 2. # echo b > /proc/sysrq-trigger 1. /proc/sys/ke ...
- BZOJ 3782 上学路线 ——动态规划 Lucas定理 中国剩余定理
我们枚举第一个经过的坏点,然后DP即可. 状态转移方程不是难点,难点在于组合数的处理. 将狼踩尽的博客中有很详细的证明过程,但是我只记住了结论 $n=a_1 * p^k+a_2*p^k-1...$ $ ...
- POJ 2154 Color ——Burnside引理
[题目分析] 数据范围有些大. 然后遍求欧拉函数,遍求和就好了,注意取模. [代码] #include <cstdio> #include <cstring> #include ...
- bzoj1063【Noi2008】道路设计
题意:http://www.lydsy.com/JudgeOnline/problem.php?id=1063 用一种划分方式将树划为重链和轻链,使得所有点到根节点的路径经过的轻链最大值最小 sol: ...
- poj 1486 Sorting Slides
Sorting Slides Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4469 Accepted: 1766 De ...