We are going to start by defining the reducer for the filter value. Let's define the filter reducer now:
- Create a new src/reducers.js file and import the generateID function from the src/api.js file:
import { generateID } from './api'
- 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.