How it works...
In step 1, we imported all of the action types that we declared in the previous recipe. We use these types to determine what action should be taken and how action.payload should affect the Redux state.
In step 2, we defined the initial state of the reducer function. For now, we only need an empty array for our photos, but we could add other properties to the state, such as Boolean properties of isLoading and didError to track loading and error states. These can, in turn, be used to update the UI during and in response to async actions.
In step 3, we defined the reducer function, which receives two parameters: the current state and the action that is being dispatched. We set the initial state to initialState if we are not provided ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access