SlideShare a Scribd company logo
Let’s make a better
React <form />
Jay Chung
Jay Chung
Front End Developer
@TrendMicro
github.com/xJkit
twitter.com/xJkit
3W1H
• Why do you need a better <form />

• When to use a better <form />

• What is a better <form />

• How to use a better <form />
WHY
• Why do you need a better <form />

• When to use a better <form />

• What is a better <form />

• How to use a better <form />
<form /> in React is simple
Lets make a better react form
Lets make a better react form
<form /> in React is simple
without validations
<form /> in real world is complicated
with validations
with multi fields
with multi forms
Sync Validation Form
Sync Validation
(Controlled Input)
Show Error Message
Input value states
Error message states
A lot of
handle functions
Prevent submission
When errors occur
Too much states and handle functions

	 	 have nothing to do with UIs…

	 	 same validation logic in different components

	 	 tedious to wire up the components every time

	 Too much repeated fields & controlled inputs

	 	 hard to reuse same field in different forms

almost the same fields repeat again & again..
WHY
• Why do you need a better <form />

• too verbose and complicated in real word cases

• When to use a better <form />

• What is a better <form />

• How to use a better <form />
WHEN
• Why do you need a better <form />

• too verbose and complicated in real word cases

• When to use a better <form />

• What is a better <form />

• How to use a better <form />
Large <form /> makes you CRAZY
WHEN
• Why do you need a better <form />

• Too verbose and complicated in real word cases

• When to use a better <form />

• while you meet a form with a lot of fields

• What is a better <form />

• How to use a better <form />
WHAT
• Why do you need a better <form />

• Too verbose and complicated in real word cases

• When to use a better <form />

• while you meet a form with a lot of fields

• What is a better <form />

• How to use a better <form />
Let’s make <form />
CLEANER
controlled/uncontrolled
component
Controlled Uncontrolled
Class component Functional component
feature controlled uncontrolled
one-time value retrieval (e.g. on submit) ✅ ✅
validating on submit ✅ ✅
instant field validation ✅ ❌
conditionally disabling submit button ✅ ❌
enforcing input format ✅ ❌
several inputs for one piece of data ✅ ❌
dynamic inputs ✅ ❌
https://goshakkk.name/controlled-vs-uncontrolled-inputs-react/
HOC
Functional component + Class container
HOC in Redux
Form UI
Component
Input value states
Error message states
Handle functions
Component Enhancer
Validate as you need
Validation
Functions
<form />
<form />
<form />
<form />
WHAT
• Why do you need a better <form />

• Too verbose and complicated in real word cases

• When to use a better <form />

• while you meet a form with a lot of fields

• What is a better <form />

• separate UI and logic

• validate as you need

• How to use a better <form />
HOW
• Why do you need a better <form />

• Too verbose and complicated in real word cases

• When to use a better <form />

• while you meet a form with a lot of fields

• What is a better <form />

• separate UI and logic

• validate as you need

• How to use a better <form />
Redux form
author @erikras
Common Input Textfield
Validate as you need

(like plugins!)
Validation
Functions
Data flow in Redux Form
decorate form 

by reduxForm()
Redux store
Input values
Error messages
What Redux-form includes
• Simple Form
• Synchronous Validation
• Field-Level Validation
• Submit Validation
• Asynchronous Blur Validation
• Initializing From State
• Field Arrays
• Remote Submit
• Normalizing
• Immutable JS
• Selecting Form Values
• Wizard Form
… more detail in documentation
You don’t want
redux?
“to create a scalable, performant, form helper with a minimal API that does
the really really annoying stuff, and leaves the rest up to you.”
@ jaredpalmer
withFormik HoC
HoC provides minimal APIs
for you
Controlled input
(only add with handleChange)
Formik comes with
a few helpers
<Form />, <Field />
to save you key
strokes and make
forms less verbose.
redux free
smaller gzipped size( 9.2k > 22.5k)
naming conventions from redux-form
HOC pattern
V.S
https://cdb.reacttraining.com/use-a-render-prop-50de598f11ce
Michael Jackson - Never Write Another HoC
The Problem with HOC
The Problem with HOC
Indirection

which HOC provides which props?

Naming Collision

Two HOCs that try to use the same prop
name will collide and overwrite one another
Render Props Pattern
(FaCC)
HoC Pattern
Render Props Pattern
The render prop gives us the state we need to render whatever we want here
Render Props Pattern
Instead of using a HOC,
we can share code using
a regular component
with a render prop!
What Render Props Solves
Indirection

don’t have to wonder where our state or props are
coming from. We can see them in the render
prop’s argument list.

Naming Collision

There is no automatic merging of property names,
so there is no chance for a naming collision.
Formik HoC to Render Props
Formik HoC to Render Props
have full access to React's state, props,
and composition model
no need to map outer props to values
render prop accepts your inner form
component, which you can define
separately or inline totally up to you
<Formik render={props =>
<form>...</form>}>
Validation Helpers
validator.js
• https://github.com/chriso/validator.js/

• A library of string validators and sanitizers

• Check available a list of validators
9k
45458/day
joi
• https://github.com/hapijs/joi

• Object schema validation

• allows you to create blueprints or schemas for JavaScript
objects (an object that stores information) to ensure validation of
key information.
6k
57016/day
joi
6k
57016/day
joi
6k
57016/day
• username
a required string
must contain only alphanumeric characters
at least 3 characters long but no more than 30
must be accompanied by birthyear
• password
an optional string
must satisfy the custom regex
cannot appear together with access_token
• access_token
an optional, unconstrained string or number
• birthyear
an integer between 1900 and 2013
• email
a valid email address string
Validation Schema
Yup
1.1k
700/day
• https://github.com/jquense/yup

• Dead simple Object schema validation

• Object schema validator and object parser

• The API and style is stolen heavily inspired by Joi

• A leaner in the same spirit without some of the fancy
features
Yup
1.1k
700/day
Formik loves Yup!
Special validationSchema
prop for Yup
V.S
redux free
smaller gzipped size( 9.2k > 22.5k)
naming conventions from redux-form
HOC pattern
render props approach
special validationSchema with Yup!
“wait…I just released a redux form without redux!”
React Final Form
1.1k
100/day
• https://github.com/final-form/react-final-form

• Only peer dependencies: React and  🏁  Final Form

• 2.7k gzipped
Thanks for your
listening

More Related Content

PDF
An introduction to React.js
PPTX
reactJS
PPTX
React JS - A quick introduction tutorial
PPTX
Introduction to React JS for beginners
PPTX
Introduction to React JS for beginners | Namespace IT
PPTX
React hooks
PPTX
What is component in reactjs
PDF
React js
An introduction to React.js
reactJS
React JS - A quick introduction tutorial
Introduction to React JS for beginners
Introduction to React JS for beginners | Namespace IT
React hooks
What is component in reactjs
React js

What's hot (20)

PDF
Introduction to React JS
PPTX
Its time to React.js
PDF
Workshop 21: React Router
PPTX
React workshop
PDF
The virtual DOM and how react uses it internally
PPTX
React hooks
PPTX
React hooks
PDF
ReactJS presentation
PPTX
Intro to React
PPTX
ReactJS presentation.pptx
PPTX
React-JS Component Life-cycle Methods
PPT
JavaScript: Events Handling
PPTX
Understanding react hooks
PPTX
React js for beginners
PPTX
React js
PPTX
Introduction to React
PDF
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
PPTX
React state
PPTX
Introduction to React JS
Its time to React.js
Workshop 21: React Router
React workshop
The virtual DOM and how react uses it internally
React hooks
React hooks
ReactJS presentation
Intro to React
ReactJS presentation.pptx
React-JS Component Life-cycle Methods
JavaScript: Events Handling
Understanding react hooks
React js for beginners
React js
Introduction to React
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
React state
Ad

Similar to Lets make a better react form (20)

PDF
The biggest lies about react hooks
PDF
React.js Form Management with Formik and Yup in UAE Projects
PDF
Redux Form | ReactJS Tutorial for Beginners | React Redux Tutorial | ReactJS ...
PDF
React Hook Form
PPT
Formik vs React-Hook-form
PPTX
Online e learning management system form.pptx
PDF
Beginner’s tutorial (part 1) integrate redux form in react native application
PPTX
Forms-in-React-Building-Interactive-User-Experiences.pptx
PDF
JavaScript - Chapter 14 - Form Handling
PDF
Angular Reactive Forms vs React Redux Form
KEY
HTML5 Form Validation
PDF
React JS Interview Questions PDF By ScholarHat
PDF
A Sensational Exposé With Bewildering Demonstrations
PDF
FormJs.pdf
PDF
How to set focus on an input field after rendering in ReactJS in 2024_.pdf
PPTX
Accessible dynamic forms
PDF
react-en.pdf
PDF
An Introduction to Formstack
PDF
Input.pdf
PPTX
form_validation_with_html5
The biggest lies about react hooks
React.js Form Management with Formik and Yup in UAE Projects
Redux Form | ReactJS Tutorial for Beginners | React Redux Tutorial | ReactJS ...
React Hook Form
Formik vs React-Hook-form
Online e learning management system form.pptx
Beginner’s tutorial (part 1) integrate redux form in react native application
Forms-in-React-Building-Interactive-User-Experiences.pptx
JavaScript - Chapter 14 - Form Handling
Angular Reactive Forms vs React Redux Form
HTML5 Form Validation
React JS Interview Questions PDF By ScholarHat
A Sensational Exposé With Bewildering Demonstrations
FormJs.pdf
How to set focus on an input field after rendering in ReactJS in 2024_.pdf
Accessible dynamic forms
react-en.pdf
An Introduction to Formstack
Input.pdf
form_validation_with_html5
Ad

More from Yao Nien Chung (6)

PDF
Use React Patterns to Build Large Scalable App
PDF
Enhance react app with patterns - part 1: higher order component
PDF
Rollup v.s Webpack: shallow compare the next generation ES6 bundlers
PDF
Javascript 攻佔桌面應用程式:使用 electron
PDF
軟體測試是在測試什麼?
PDF
前端爆肝之旅+React上山前的小專案心得分享
Use React Patterns to Build Large Scalable App
Enhance react app with patterns - part 1: higher order component
Rollup v.s Webpack: shallow compare the next generation ES6 bundlers
Javascript 攻佔桌面應用程式:使用 electron
軟體測試是在測試什麼?
前端爆肝之旅+React上山前的小專案心得分享

Recently uploaded (20)

PDF
medical staffing services at VALiNTRY
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PDF
Understanding Forklifts - TECH EHS Solution
PDF
Cost to Outsource Software Development in 2025
PDF
Nekopoi APK 2025 free lastest update
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
iTop VPN Free 5.6.0.5262 Crack latest version 2025
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
history of c programming in notes for students .pptx
PDF
Digital Strategies for Manufacturing Companies
PPTX
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
PDF
Digital Systems & Binary Numbers (comprehensive )
PPTX
Why Generative AI is the Future of Content, Code & Creativity?
PPTX
Introduction to Artificial Intelligence
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
medical staffing services at VALiNTRY
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
Understanding Forklifts - TECH EHS Solution
Cost to Outsource Software Development in 2025
Nekopoi APK 2025 free lastest update
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
iTop VPN Free 5.6.0.5262 Crack latest version 2025
Design an Analysis of Algorithms I-SECS-1021-03
Odoo Companies in India – Driving Business Transformation.pdf
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
wealthsignaloriginal-com-DS-text-... (1).pdf
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Design an Analysis of Algorithms II-SECS-1021-03
history of c programming in notes for students .pptx
Digital Strategies for Manufacturing Companies
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
Digital Systems & Binary Numbers (comprehensive )
Why Generative AI is the Future of Content, Code & Creativity?
Introduction to Artificial Intelligence
Upgrade and Innovation Strategies for SAP ERP Customers

Lets make a better react form