此问题是在升级到最新架构后出现的。 此外,只有某些部分被清除,例如loggedInUser和主页列表。
Environment and Setup:
Device:
iPhone 16 Pro, iOS 18.1 Simulator and in Actual Testflight
React Native Version:
0.76.3 with New Architecture Enabled
Other Relevant Libraries:
mobx: "^6.13.5",
mobx-react: "^9.1.1",
react-navigation: 7.x.x
修复了 MobX 存储初始化逻辑
[旧代码]
let store: RootStore;
// create the context
const StoreContext = createContext<RootStore | undefined>(undefined);
// create the provider component
export function RootStoreProvider({ children }: { children: ReactNode }) {
//only create the store once ( store is a singleton)
const root = store ?? new RootStore();
return <StoreContext.Provider value={root}>{children}</StoreContext.Provider>;
}
[新代码]
// Singleton store variable
let store: RootStore | undefined;
// Create the context
const StoreContext = createContext<RootStore | undefined>(undefined);
// RootStoreProvider Component
export function RootStoreProvider({ children }: { children: ReactNode }) {
// Initialize the store only once
if (!store) {
store = new RootStore();
}
return <StoreContext.Provider value={store}>{children}</StoreContext.Provider>;
}