【model 互相依赖问题】Warning: Cannot update a component (`Executor`) while
alvin0216 opened this issue · comments
import { FC, useState, useEffect } from 'react';
import { createModel } from 'hox';
const useCounterModel = createModel(() => {
const [count, setCount] = useState(0);
const increment = () => setCount(count + 1);
return {
count,
increment,
};
});
const useCounterModel2 = createModel(() => {
const counterModel = useCounterModel();
const [count, setCount] = useState(counterModel?.count || 0 + 1);
const increment = () => setCount(count + 1);
return {
count,
increment,
};
});
const App: FC = () => {
const counterModel = useCounterModel();
const counterModel2 = useCounterModel2();
return (
<>
{counterModel.count} | {counterModel2.count}
<button onClick={counterModel.increment}>increment</button>
</>
);
};
export default App;
是否是我的使用姿势有问题?
发现 model 相互依赖,很容易出现这样的问题
也遇到了这个问题,觉得有点奇怪
有解决吗
遇到+1,有解决方案吗