React Hook useEffect has a missing dependency: 'dispatch'

Reactjs

This is my first time working with react js , im trying to remove the alert when leaving this view cause i don't want to show it on the other view but in case that there is no error i want to keep the success alert to show it when i'm gonna redirect to the other view

but im getting this wearning on google chrome Line 97:6: React Hook useEffect has a missing dependency: 'dispatch'. Either include it or remove the dependency array react-hooks/exhaustive-deps

if i did include dispatch i get infinite loop

const [state, dispatch] = useUserStore();useEffect(() => {    let token = params.params.token;    checktoken(token, dispatch);  }, [params.params.token]);  useEffect(() => {    return () => {      if (state.alert.msg === "Error") {        dispatch({          type: REMOVE\_ALERT        });      }    };  }, [state.alert.msg]);//response from the apiif (!token_valide || token_valide_message === "done") {      return <Redirect to="/login" />;    }

this is useUserStore

  const globalReducers = useCombinedReducers({    alert: useReducer(alertReducer, alertInitState),    auth: useReducer(authReducer, authInitState),    register: useReducer(registerReducer, registerInitState),    token: useReducer(passeditReducer, tokenvalidationInitState)  });  return (    <appStore.Provider value={globalReducers}>{children}</appStore.Provider>  );};export const useUserStore = () => useContext(appStore);

Answer link : https://codehunter.cc/a/reactjs/react-hook-useeffect-has-a-missing-dependency-dispatch

Posted Mar 22, 2022, 9:24 PM UTC

10
Loading comments…