A More Complex Example
The previous examples were deliberately rather simple. Now that the basics of custom Hooks are clear, it makes sense to dive into a slightly more advanced and realistic example.
Consider the HTTP request example from the beginning of this chapter:
const initialHttpState = { data: null, isLoading: false, error: null, }; function httpReducer(state, action) { if (action.type === 'FETCH_START') { return { ...state, // copying the existing state isLoading: state.data ? false : true, error: null, }; } if (action.type === 'FETCH_ERROR') { return { data: null, isLoading: false, error: action...