arh*_*nee 9 mobx mobx-react mobx-react-lite
在mobx-react 文档中,store 的创建方式存在差异。例如,在React Context页面上:
在第一个代码示例中,商店使用 useLocalStore 实例化:
const store = useLocalStore(createStore)
Run Code Online (Sandbox Code Playgroud)
在第二个代码示例中,商店是通过直接“新建”商店来启动的:
counterStore: new CounterStore(),
themeStore: new ThemeStore(),
Run Code Online (Sandbox Code Playgroud)
通过推断,第一个是“本地”存储(因此需要 useLocalStore),第二个是“全局”存储,因此不需要。然而,目前尚不清楚这是为什么,以及随后的行为差异是什么。
为什么useLocalStore在第二个例子中不需要,这对 React 中的 store 和 mobx 的行为有什么不同?
感谢您提供任何意见
| 归档时间: |
|
| 查看次数: |
4296 次 |
| 最近记录: |