Defining the filter reducer

We are going to start by defining the reducer for the filter value. Let's define the filter reducer now:

  1. Create a new src/reducers.js file and import the generateID function from the src/api.js file:
import { generateID } from './api'
  1. In the src/reducers.js file, define a new function, which is going to handle the FILTER_TODOS action, and set the value accordingly:
function filterReducer (state, action) {
if (action.type === 'FILTER_TODOS') {
return action.filter
} else {
return state
}
}

Now, the filterReducer  function is defined, and we can handle the FILTER_TODOS action properly.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.140.108