[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 提供了一组标 ...
随机推荐
- The Three Day
函数基础-练习 #.写函数,,用户传入修改的文件名,与要修改的内容,执行函数,完成批了修改操作 # def modify_file(filename,old,new): # import os # w ...
- 关于Python解释器
由于Python语言从规范到解释器都是开源的,所以理论上任何人都可以编写Python解释器来执行Python代码 目前存在以下几种主流的Python解释器 CPython CPython是官方版本的解 ...
- Makefile学习(一)----初步理解
一.我对makefile的理解: 经过一段时间对makefile的学习,我理解的makefile就是将程序员手动编译源文件的过程用一个脚本执行,这对于小型项目来说,程序员手动执行和用makefile来 ...
- redis安装与安全设置
redis Redis 是一个开源(BSD许可)的,内存中的数据结构存储系统,它可以用作数据库.缓存和消息中间件 yum安装redis 1.yum安装 #前提得配置好阿里云yum源,epel源 # ...
- 基于注解实现SpringBoot多数据源配置
1.功能介绍 在实际的开发中,同一个项目中使用多个数据源是很常见的场景.最近在学习的过程中使用注解的方式实现了一个Springboot项目多数据源的功能.具体实现方式如下. 2.在applicatio ...
- git删除本地所有的更改
删除本地所有为暂存的修改: git checkout -f 如果有修改以及加入暂存区的话 那么 使用如下命令: git reset --hard git clean -xdf
- xtu数据结构 C. Ultra-QuickSort
C. Ultra-QuickSort Time Limit: 7000ms Memory Limit: 65536KB 64-bit integer IO format: %lld Java ...
- SQL indexOf、lastIndexOf
DECLARE @Name NVARCHAR (50)SET @Name = 'abcd.12345.efght' DECLARE @Position INT --sql first indexofS ...
- python 向MySQL里插入中文数据
用python向MySQL中插入中文数据出错,原代码片段: 1 db = MySQLdb.connect("localhost","root","12 ...
- LightOJ——1066Gathering Food(BFS)
1066 - Gathering Food PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB W ...