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. vue ssr

    https://mp.weixin.qq.com/s/v1c69bJ5PxGcqt-ZU4FVXw https://juejin.im/entry/590ca74b2f301e006c10465f h ...

  2. Python模块概念

    补充:生成器表达式 将列表生成器的中括号改为小括号就是生成器表达式 res = [i for i in range(10) if i > 5]  #  列表生成式 res = (i for i ...

  3. 20181121笔记(for,数字类型和字符串类型的内置方法)

    1.for循环 for循环可以遍历任何序列的项目,如一个列表或者一个字符串. for循环字典时默认取出key: dic={'x':111,'y':222,'z:333'}​for k in dic:​ ...

  4. Mining of Massive Datasets-1

    given lots of data->discover patterns and models that are: valid, useful, unexpected, understanda ...

  5. NSArray 排序

    先研究一种方法 NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:]; ; i < ; i++) { ; [arr ...

  6. JavaScript正则表达式-字符

    普通字符 大小写字母.数字.其他任何符号. 转义字符 转义字符 含义 \f 换页符 \n 换行符 \r 回车符 \t 制表符 \b 退格符 \o 空字符 \xnn 由十六进制数nn指定的ASCII码对 ...

  7. PAT Basic 1066

    1066 图像过滤 图像过滤是把图像中不重要的像素都染成背景色,使得重要部分被凸显出来.现给定一幅黑白图像,要求你将灰度值位于某指定区间内的所有像素颜色都用一种指定的颜色替换. 输入格式: 输入在第一 ...

  8. intellij idea 17 log4j 中文乱码

    先是在intellij idea里设置没有得到解决, 然后在tomcat的server.xml里设置没有得到解决, 再然后在log4j配置文件里配置没有得到解决. 以下是解决方案. C:\Progra ...

  9. shell-001

    for: shell_test #!/bin/bash var= var=$var+ echo $var mkdir only_a_joke shell_joke #!/bin/bash ./shel ...

  10. Codeforces Round #390 (Div. 2) A+B+D!

    A. Lesha and array splitting 水题模拟.(0:10) 题意:给你一个n个元素的数组,求能否把这个数组分成若干连续小段,使得每段的和不为0.如有多种解输出任意一个. 思路:搞 ...