Anyway to access the rootStore without using context / useRootstore hook
geohuz opened this issue · 2 comments
geohuz commented
In react-router v6 there is a data router which expose function action/loader
calls fetch api, but these functions are out of component scope, I'm wondering how can I reference the rootStore from the normal function?
k-ode commented
Yes, you can initialize the query client manually.
export const queryClient = new QueryClient({ RootStore });
queryClient.init(initialData, env); // internally calls RootStore.create(initialData, env)
const rootStore = queryClient.rootStore;