代码报错:
eslint 检查:
React Hook “useModel” is called conditionally. React Hooks must be called in the exact same order in every component render. Did you accidentally call a React Hook after an early return? react-hooks/rules-of-hooks
翻译:
React Hook“useModel”是有条件调用的。在每个组件渲染中,必须以完全相同的顺序调用React Hooks。你是不是在提前回来后不小心叫了React Hook?反作用钩子/钩子规则
解决办法:
useModel 调用必须写在函数的方法的最顶部,这个报错原因之一就是因为 从 model 中解构数据的时候把语句没写在 最顶部
例如这样:
将model写到最顶部就好了
有时候这个翻译挺误导人,我一直以为是递归组件model循环引入问题,汗!