All Projects → jaredpalmer → Formik Effect

jaredpalmer / Formik Effect

Licence: mit
Declarative component for managing side-effects in Formik forms. 580 bytes

Programming Languages

typescript
32286 projects

Labels

Projects that are alternatives of or similar to Formik Effect

Vue Formulate
⚡️ The easiest way to build forms with Vue.
Stars: ✭ 1,947 (+1116.88%)
Mutual labels:  form
Forms
📝 Simple form & survey app for Nextcloud
Stars: ✭ 127 (-20.62%)
Mutual labels:  form
Vue Ui For Pc
基于Vue2.x的一套PC端UI组件,包括了Carousel 跑马灯、Cascader 级联、Checkbox 多选框、Collapse 折叠面板、DatePicker 日期选择、Dialog 对话框、Form 表单、Input 输入框、InputNumber 数字输入框、Layer 弹窗层、Loading 加载、Menu 菜单、Page 分页、Progress 进度条、Radio 单选框、SelectDropDown 仿select、Switch 开关、Table 表格、Tabs 标签页、Textarea 文本框、Tooltip 文字提示、BackTop 返回顶部、steps 步骤条、Transfer 穿梭框、Tree 树形、Upload 文件上传、Lazy 图片懒加载、Loading 加载、Pagination 分页等等
Stars: ✭ 156 (-2.5%)
Mutual labels:  form
React Controlled Form
Flexible, Modular & Controlled Forms for React and Redux
Stars: ✭ 121 (-24.37%)
Mutual labels:  form
Form Validation.js
The most customizable validation framework for JavaScript.
Stars: ✭ 127 (-20.62%)
Mutual labels:  form
Antd Schema Form
Based on Ant Design, interactive forms can be generated through JSON Schema configuration. - 基于Ant Design,可以通过JSON Schema配置生成可交互的表单。
Stars: ✭ 137 (-14.37%)
Mutual labels:  form
React Form With Constraints
Simple form validation for React
Stars: ✭ 117 (-26.87%)
Mutual labels:  form
Swform
iOS 高度封装自适应表单(重构版)
Stars: ✭ 159 (-0.62%)
Mutual labels:  form
Avue
Avue.js2.0是基于现有的element-ui库进行的二次封装,简化一些繁琐的操作,核心理念为数据驱动视图,主要的组件库针对table表格和form表单场景,同时衍生出更多企业常用的组件,达到高复用,容易维护和扩展的框架,同时内置了丰富了数据展示组件,让开发变得更加容易
Stars: ✭ 1,789 (+1018.13%)
Mutual labels:  form
Formhelper
ASP.NET Core - Transform server-side validations to client-side without writing any javascript code. (Compatible with Fluent Validation)
Stars: ✭ 155 (-3.12%)
Mutual labels:  form
Edit In Place
A flexible and unopinionated edit in place library for Angular applications
Stars: ✭ 123 (-23.12%)
Mutual labels:  form
Fonk
Form schema validation library
Stars: ✭ 125 (-21.87%)
Mutual labels:  form
Convform
A jQuery plugin that transforms a form into an interactive chat.
Stars: ✭ 141 (-11.87%)
Mutual labels:  form
Vue Form Components
Clean & minimal vue form elements and form builder with validation
Stars: ✭ 120 (-25%)
Mutual labels:  form
Core
The Form Tools Core.
Stars: ✭ 156 (-2.5%)
Mutual labels:  form
Form For
ReactJS forms made easy
Stars: ✭ 118 (-26.25%)
Mutual labels:  form
Reactive forms
This is a model-driven approach to handling form inputs and validations, heavily inspired in Angular's Reactive Forms
Stars: ✭ 135 (-15.62%)
Mutual labels:  form
Fielder
A field-first form library for React and React Native
Stars: ✭ 160 (+0%)
Mutual labels:  form
Vuetify Form Base
Schema-based Form Generator - Vue.js 2.0 Component based on Vuetify 2.0
Stars: ✭ 157 (-1.87%)
Mutual labels:  form
React Native Form
A simple react-native component to wrap your form fields and get their values with just one single method.
Stars: ✭ 146 (-8.75%)
Mutual labels:  form

Formik Effect

Declarative Formik component for side-effects. Use with caution. Please. I. beg. you.

npm install formik-effect --save

Note: this has peer dependencies of prop-types, react, and formik (obvs)

The Problem

Formik is an uncontrolled component. However, there are times when you want to trigger a side effect based on a state change. By design, Formik does not expose a prop for you to do this because I'm terrified as to how it would be abused--it encourages people to attempt to "sync" Formik's state in elsewhere (cough like in a Redux store cough cough). Anyways, please don't do that. You never ever ever ever want to store the same state in 2 places in a React application because it is almost impossible to keep them in sync unless you are a goddamn jedi. You may think it's working, and high five a teammate, but you are a just a lifecycle method away from lots and lots of pain and I can guarantee you are not considering all the edge cases. Sooooo....

SAY IT WITH ME:

"I WILL NOT USE THIS TO STORE FORMIK STATE ELSEWHERE IN MY APP."
"I WILL NOT USE THIS TO STORE FORMIK STATE ELSEWHERE IN MY APP."
"I WILL NOT USE THIS TO STORE FORMIK STATE ELSEWHERE IN MY APP."

Basic Usage

Import the <Effect > component and put it inside any Formik form. It renders null! Pass it an onChange() function and it will be called whenever your Formik form's state updates.

import React from 'react'
import { Formik, Field, Form } from 'formik'
import { Effect } from 'formik-effect'

export const Signup = () =>
  <div>
    <h1>My Cool Form with a SideEffect</h1>
    <Formik
      onSubmit={values => console.log(values)}
      initialValues={{ firstName: '', lastName: '', email: '' }}
      render={props =>
        <Form className="whatever">
          <Effect onChange={(currentFormikState, nextFormikState) => {
               // do whatevs
               // FYI if you alter state it will cause another render
            }} 
          />
          <Field name="firstName" placeholder="First Name" />
          <Field name="lastName" placeholder="Last Name" />
          <Field name="email" type="email" placeholder="Email Address" />
          <button type="submit">Submit</button>
         
        </Form>}
    />
  </div>;

API

Only one!

onChange: (currentState: FormikState<Values>, nextState: FormikState<Values> => void

Put your side effect here.

FormikState includes:

  • values
  • errors
  • touched
  • isSubmitting

Under the hood this calls componentWillReceiveProps(). When Formik refactors for React 16.3, it will use componentDidUpdate. Either way, it does shallow comparison on context with triple equals, which may not be what you want. Luckily, this whole component is like 500 bytes so you could just copy pasta it into your app.

Future Work

When Formik is updated to React 16.3, this library will need to be updated for use without PropTypes.

Author

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].