首页 > 解决方案 > 在刷新之前,Mobx 状态不会在 App.js 中更新

问题描述

我在使用 Mobx 时遇到了一个小问题,其中状态到处都发生了很好的变化,但在 App.js 中却没有。我怎样才能实现它也直接在 App.js 中更新而无需刷新?

应用程序.js:


function App() {
const [rootStore, setRootStore] = useState<RootStore | undefined>(undefined)

(...)

 // Kick off initial async loading actions, like loading fonts and RootStore
  useEffect(() => {
    ;(async () => {
      await initFonts() // expo
      setupRootStore().then(setRootStore)
    })()
  }, [])


<ApplicationProvider {...eva} theme={rootStore.mode.dark ? eva.dark : eva.light}>
(...)
</ApplicationProvider>
}

标签: react-nativemobx-react

解决方案


推荐阅读