DEV Community

Discussion on: Refactoring An Old React App: Creating a Custom Hook to Make Fetch-Related Logic Reusable

Collapse
 
lostrogoth profile image
Lostrogoth

case REQUEST_STARTED:
// Avoid updating state unnecessarily
// By returning unchanged state React won't re-render

if (state.isLoading) {
return state;
}
return {
...state,
isLoading: true,
};

Collapse
 
pallymore profile image
Yurui Zhang

Hi - thanks for the comment.

personally i don't think that's necessary - if REQUEST_STARTED is fired multiple times when it is already loading, I would think there are more serious problems in other parts of the app, not just in the reducer.