我尝试更新状态中的数据,但返回错误 页面刷新时发生错误
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]);
错误类型...
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
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^