How to do it...

The validations are needed in any form, so let's add some validations to our fields:

  1. First, we need to modify our TodoForm.jsx and we need to create a validate function, where we need to validate if our task is not empty. We then need to create a renderError method to render our error message if we try to add an empty task, as shown in the following code:
import React, { Component } from 'react';import { Field, reduxForm } from 'redux-form';import './TodoForm.css';class TodoForm extends Component {  renderInput = ({ input }) => <input {...input} type="text" />;  onSubmit = values => {    const { addTask, dispatch, reset } = this.props;    // Resetting our form...    dispatch(reset('todo'));    addTask(values);  }  renderError(field) {

Get React Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.