diff --git a/src/useFetch/index.ts b/src/useFetch/index.ts index a291f03..4a1bddf 100644 --- a/src/useFetch/index.ts +++ b/src/useFetch/index.ts @@ -25,8 +25,8 @@ type ActionMap = { type Actions = ActionMap>[keyof ActionMap>]; const reducer = (state: State, action: Actions): State => { - 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 }; };