Integration of React Components with Redux Form

This guide demonstrates how to integrate Syncfusion® React components in Redux Form, covering project setup, store configuration, form implementation, validation, and running the application.

What is Redux Form?

Redux Form is a popular library used in React projects for managing and handling form state. It integrates seamlessly with the Redux state management library (Redux Store) and provides an efficient way to manage form inputs, validation, submission, and data synchronization with the Redux store.

Set up the React project

1. Create a new React project using Vite.

2. Install the necessary Redux dependencies by running the following command:

The redux-form package is not officially supported in React 19. It is recommended to use React 18 for compatibility. If you want to use React 19, you may encounter dependency issues. To resolve this, install the packages with the --legacy-peer-deps flag.

Create a Redux Form

1. Create a new file named LoginForm.tsx and implement the login form using Redux Form:

2. Include the form component and its associated styles in your React project by adding the following code to the App.tsx and App.css files:

Setting up the Redux store

After creating the form and integrating it into the React project, set up the Redux store in the main.tsx file. Use the Provider component to make the Redux store available to all child components in the application. This enables the form state and other application state to be managed globally through Redux.

Connecting the form to Redux

In the LoginForm.tsx file, connect the form component with Redux Form by exporting it using the reduxForm higher-order component:

Adding Syncfusion® React components

To add Syncfusion® React components Button and TextBox into the login form, follow these steps:

1. Install the required Syncfusion® packages

2. Import the required CSS files for the Button and TextBox components into the src/App.css file.

3. Integrate the React components into the login form by using the Field component provided by Redux Form.

4. Define a handler function for form submission and data display in the App.tsx and LoginForm.tsx files:

Form validation

Redux Form provides built-in support for validation. Implement a validate function to check form values and display error messages when needed. Validation occurs automatically on submission.

Displaying validation errors

Upon form submission, the inputs will be validated and corresponding error messages will be displayed below the respective input fields.

Run the project

Execute the following command to run the project:

The output will appear as follows:

Redux form