1

I try to update data in the state, but I got error back The error happens when the page refresh

const [local, setLocal] = React.useState(initialState || []);
React.useEffect(() => {
    getLocal();
}, []);
const getLocal = async () => {
    try {
        let lo = await _getData();
        if (lo != null) {
            setLocal(pre=>({...pre, ...lo});
        }
    } catch (err) {
        console.log(err);
    }
};
const [state, dispatch] = React.useReducer(reducer, local);
const store = React.useMemo(() => ({...state, dispatch}), [state]);

Type of error ...

ERROR  Warning: React has detected a change in the order of 
Hooks called by App. This will lead to bugs and errors if not fixed.

   Previous render            Next render
   ------------------------------------------------------
1. useState                   useState
2. useMemo                    useEffect
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  • did you see this solution? - https://stackoverflow.com/questions/57397395/react-has-detected-a-change-in-the-order-of-hooks-but-hooks-seem-to-be-invoked. I believe it's something related to the store variable. – tomer raitz Jun 12 '21 at 15:44
  • That doesn't solve yet! – NOP PHEARUM Jun 12 '21 at 15:56

0 Answers0