Skip to content

Commit

Permalink
Reset error and data in useFetch in case of cross action
Browse files Browse the repository at this point in the history
  • Loading branch information
knightburton committed Jan 6, 2022
1 parent 8355aa6 commit 45f9d11
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/useFetch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ type ActionMap<M extends { [key: string]: any }> = {
type Actions<T> = ActionMap<Payload<T>>[keyof ActionMap<Payload<T>>];

const reducer = <T>(state: State<T>, action: Actions<T>): State<T> => {
if (action.type === ActionTypes.Success) return { ...state, data: action.payload, loading: false };
if (action.type === ActionTypes.Failure) return { ...state, error: action.payload, loading: false };
if (action.type === ActionTypes.Success) return { ...state, data: action.payload, loading: false, error: undefined };
if (action.type === ActionTypes.Failure) return { ...state, error: action.payload, loading: false, data: undefined };
return { ...state, loading: action.payload };
};

Expand Down

0 comments on commit 45f9d11

Please sign in to comment.