Top Related Projects
A Higher Order Component using react-redux to keep form state in a Redux store
Build forms in React, without the tears 😭
🏁 High performance subscription-based form state management for React
🤖 Powerful and type-safe form state management for the web. TS/JS, React Form, Solid Form, Lit Form and Vue Form.
Performance-focused API for React forms 🚀
📋 React Hooks for form state management and validation (Web + React Native)
Quick Overview
React Redux Form is a library that simplifies form management in React applications using Redux. It provides a set of components and utilities to handle form state, validation, and submission, integrating seamlessly with Redux for state management.
Pros
- Seamless integration with Redux for centralized state management
- Built-in form validation and error handling
- Supports both controlled and uncontrolled form components
- Extensive documentation and examples available
Cons
- Learning curve for developers new to Redux
- Can be overkill for simple forms or small applications
- Requires additional setup compared to native React forms
- Less active maintenance in recent years
Code Examples
- Creating a simple form:
import { Control, Form } from 'react-redux-form';
const SimpleForm = () => (
<Form model="user">
<label>Name:</label>
<Control.text model=".name" />
<button type="submit">Submit</button>
</Form>
);
- Adding form validation:
import { Control, Form, Errors } from 'react-redux-form';
const required = (val) => val && val.length;
const ValidatedForm = () => (
<Form model="user" validators={{ name: { required } }}>
<label>Name:</label>
<Control.text model=".name" />
<Errors model=".name" messages={{ required: 'Name is required' }} />
<button type="submit">Submit</button>
</Form>
);
- Handling form submission:
import { Control, Form } from 'react-redux-form';
const handleSubmit = (values) => {
console.log('Form submitted with values:', values);
};
const SubmittableForm = () => (
<Form model="user" onSubmit={handleSubmit}>
<label>Email:</label>
<Control.text model=".email" />
<button type="submit">Submit</button>
</Form>
);
Getting Started
To use React Redux Form in your project:
-
Install the package:
npm install react-redux-form
-
Set up Redux in your application if not already done.
-
Import and use the components in your React components:
import { Control, Form } from 'react-redux-form'; const MyForm = () => ( <Form model="myForm"> <Control.text model=".name" /> <button>Submit</button> </Form> );
-
Connect your form to Redux state using the
combineForms
reducer:import { combineForms } from 'react-redux-form'; const initialState = { name: '' }; const rootReducer = combineForms({ myForm: initialState, });
Competitor Comparisons
A Higher Order Component using react-redux to keep form state in a Redux store
Pros of redux-form
- More mature and widely adopted in the React community
- Extensive documentation and community support
- Seamless integration with Redux store
Cons of redux-form
- Heavier bundle size due to more features
- Steeper learning curve for beginners
- Tighter coupling with Redux, less flexible for non-Redux projects
Code Comparison
redux-form:
import { reduxForm, Field } from 'redux-form';
const MyForm = ({ handleSubmit }) => (
<form onSubmit={handleSubmit}>
<Field name="username" component="input" type="text" />
<button type="submit">Submit</button>
</form>
);
export default reduxForm({ form: 'myForm' })(MyForm);
react-redux-form:
import { Control, Form } from 'react-redux-form';
const MyForm = () => (
<Form model="user">
<Control.text model=".username" />
<button>Submit</button>
</Form>
);
export default MyForm;
Both libraries aim to simplify form management in React applications, but they differ in their approach and integration with Redux. redux-form is more tightly integrated with Redux and offers a wider range of features, while react-redux-form provides a more lightweight and flexible solution. The choice between the two depends on project requirements, team familiarity, and the desired level of Redux integration.
Build forms in React, without the tears 😭
Pros of Formik
- Lightweight and flexible, with no dependencies on Redux
- Simpler API and easier to get started with
- Better performance due to minimized re-renders
Cons of Formik
- Less built-in functionality compared to react-redux-form
- May require additional libraries for complex form scenarios
- Lacks some advanced features like dynamic form generation
Code Comparison
Formik:
import { Formik, Form, Field } from 'formik';
<Formik initialValues={{ name: '' }} onSubmit={handleSubmit}>
<Form>
<Field name="name" />
<button type="submit">Submit</button>
</Form>
</Formik>
react-redux-form:
import { Control, Form } from 'react-redux-form';
<Form model="user" onSubmit={handleSubmit}>
<Control.text model=".name" />
<button type="submit">Submit</button>
</Form>
Both libraries aim to simplify form handling in React applications, but they take different approaches. Formik focuses on being lightweight and easy to use, making it a good choice for simpler forms or projects that don't use Redux. react-redux-form, on the other hand, provides more built-in functionality and integrates tightly with Redux, which can be beneficial for complex applications already using Redux for state management.
🏁 High performance subscription-based form state management for React
Pros of react-final-form
- Lightweight and performant, with no external dependencies
- More flexible and easier to customize without Redux
- Better support for dynamic forms and conditional fields
Cons of react-final-form
- Less integrated with Redux ecosystem
- Steeper learning curve for developers familiar with Redux-Form
- Fewer built-in features compared to react-redux-form
Code Comparison
react-final-form:
import { Form, Field } from 'react-final-form'
<Form
onSubmit={onSubmit}
render={({ handleSubmit }) => (
<form onSubmit={handleSubmit}>
<Field name="firstName" component="input" />
</form>
)}
/>
react-redux-form:
import { Control, Form } from 'react-redux-form'
<Form model="user" onSubmit={onSubmit}>
<Control.text model=".firstName" />
</Form>
react-final-form offers a more concise and flexible API, allowing for easier customization of form fields and behavior. It doesn't require Redux integration, making it more adaptable to different project structures. However, react-redux-form provides tighter integration with Redux and may be more familiar to developers already using Redux in their projects. The choice between the two largely depends on project requirements, team expertise, and existing architecture.
🤖 Powerful and type-safe form state management for the web. TS/JS, React Form, Solid Form, Lit Form and Vue Form.
Pros of TanStack Form
- Framework-agnostic, supporting React, Vue, Solid, and more
- Lightweight and performant, with minimal re-renders
- Flexible API with powerful validation and error handling
Cons of TanStack Form
- Steeper learning curve due to its more complex API
- Less opinionated, requiring more setup for advanced use cases
Code Comparison
react-redux-form:
import { Control, Form, actions } from 'react-redux-form';
<Form model="user" onSubmit={handleSubmit}>
<Control.text model=".name" />
<Control.text model=".email" />
<button>Submit</button>
</Form>
TanStack Form:
import { useForm } from '@tanstack/react-form'
const form = useForm({
defaultValues: { name: '', email: '' },
onSubmit: handleSubmit,
})
<form.Provider>
<form.Field name="name" children={({ field }) => <input {...field} />} />
<form.Field name="email" children={({ field }) => <input {...field} />} />
<button type="submit">Submit</button>
</form.Provider>
Summary
TanStack Form offers greater flexibility and framework support, making it suitable for diverse projects. However, it may require more setup and has a steeper learning curve. react-redux-form is more opinionated and tightly integrated with Redux, which can be advantageous for React-Redux applications but limiting for other use cases. The choice between the two depends on project requirements, team expertise, and desired level of control over form management.
Performance-focused API for React forms 🚀
Pros of Unform
- Lightweight and performant, with minimal re-renders
- Framework-agnostic, supporting React, React Native, and Vue
- Easy integration with schema validation libraries like Yup
Cons of Unform
- Less mature ecosystem compared to React Redux Form
- Fewer built-in form components and validators
- May require more custom implementation for complex form scenarios
Code Comparison
Unform:
import { Form } from '@unform/web';
import Input from './components/Input';
function MyForm() {
const handleSubmit = (data) => {
console.log(data);
};
return (
<Form onSubmit={handleSubmit}>
<Input name="email" />
<button type="submit">Submit</button>
</Form>
);
}
React Redux Form:
import { Control, Form, actions } from 'react-redux-form';
function MyForm() {
return (
<Form model="user" onSubmit={(val) => console.log(val)}>
<Control.text model=".email" />
<button>Submit</button>
</Form>
);
}
Summary
Unform offers a lightweight, flexible solution for form management across multiple frameworks, while React Redux Form provides a more established ecosystem with deeper Redux integration. Unform's simplicity and performance come at the cost of fewer built-in features, whereas React Redux Form offers more out-of-the-box functionality but with a steeper learning curve and Redux dependency.
📋 React Hooks for form state management and validation (Web + React Native)
Pros of react-hook-form
- Lightweight and performant, with minimal re-renders
- Easy to use with React Hooks, reducing boilerplate code
- Built-in validation and error handling
Cons of react-hook-form
- Less integration with Redux ecosystem
- May require additional setup for complex form scenarios
- Limited built-in form state management compared to react-redux-form
Code Comparison
react-hook-form:
import { useForm } from "react-hook-form";
const { register, handleSubmit } = useForm();
const onSubmit = data => console.log(data);
<form onSubmit={handleSubmit(onSubmit)}>
<input {...register("firstName")} />
<input type="submit" />
</form>
react-redux-form:
import { Control, Form, actions } from 'react-redux-form';
<Form model="user" onSubmit={(val) => console.log(val)}>
<Control.text model=".firstName" />
<button>Submit</button>
</Form>
react-hook-form offers a more concise and hook-based approach, while react-redux-form provides tighter integration with Redux and more built-in form management features. The choice between the two depends on project requirements, Redux usage, and developer preferences.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
React Redux Form
â ï¸ This project is in maintenance mode only. Please consider using Formik instead.
Read the Documentation
React Redux Form is a collection of reducer creators and action creators that make implementing even the most complex and custom forms with React and Redux simple and performant.
npm install react-redux-form@latest --save
Installation
# Dependencies (you probably already have these)
npm install react react-dom redux react-redux --save
# version 1.x.x
npm install react-redux-form@latest --save
Zero-Boilerplate <LocalForm>
If you want to get up and running with forms quickly without having to set up Redux, just use Local Forms:
import React from 'react';
import { LocalForm, Control } from 'react-redux-form';
export default class MyApp extends React.Component {
handleChange(values) { ... }
handleUpdate(form) { ... }
handleSubmit(values) { ... }
render() {
return (
<LocalForm
onUpdate={(form) => this.handleUpdate(form)}
onChange={(values) => this.handleChange(values)}
onSubmit={(values) => this.handleSubmit(values)}
>
<Control.text model=".username" />
<Control.text model=".password" />
</LocalForm>
);
}
}
That's all you need. Seriously. Read the Documentation for more information.
NOTE: Please use <LocalForm>
with react-redux
version 4.x.x or 5.x.x.
Quick Start
For more fine-grained control (such as using custom reducers, storing form state globally, dispatching actions, etc.), you'll want to set up a Redux store for your forms.
Be sure to read the step-by-step quick start guide in the documentation.
import React from 'react';
import { createStore } from 'redux';
import { Provider } from 'react-redux';
import { combineForms } from 'react-redux-form';
import MyForm from './components/my-form-component';
const initialUser = { name: '' };
const store = createStore(combineForms({
user: initialUser,
}));
class App extends React.Component {
render() {
return (
<Provider store={ store }>
<MyForm />
</Provider>
);
}
}
// ./components/my-form-component.js'
import React from 'react';
import { connect } from 'react-redux';
import { Control, Form } from 'react-redux-form';
class MyForm extends React.Component {
handleSubmit(val) {
// Do anything you want with the form value
console.log(val);
}
render() {
return (
<Form model="user" onSubmit={(val) => this.handleSubmit(val)}>
<label>Your name?</label>
<Control.text model=".name" />
<button>Submit!</button>
</Form>
);
}
}
// No need to connect()!
export default MyForm;
Posting Issues
When posting an issue, please include a detailed description along with a relevant code sample. Attaching a failing test case with your issue will go a long way and is much appreciated.
Feel free to fork this CodePen or this CodeSandbox for quickly creating reproducible examples!
Top Related Projects
A Higher Order Component using react-redux to keep form state in a Redux store
Build forms in React, without the tears 😭
🏁 High performance subscription-based form state management for React
🤖 Powerful and type-safe form state management for the web. TS/JS, React Form, Solid Form, Lit Form and Vue Form.
Performance-focused API for React forms 🚀
📋 React Hooks for form state management and validation (Web + React Native)
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot