createResource and createContext
Hey!
I want avoid prop-drilling for a large resource that is referenced and used by many leaf components.. is there any recommanded way of settinng up createResource with createContext.. i'm having trouble with useContext, as the leafs are rendered when the provider is not ready with a context value.. what is best-pratice or an idomatic way to combine these two primitives together?
3 Replies
you could either pass the resource, or you could use a getter too:
then in the child components where you consume that context you will have to do checks if the resource is already defined or not
Or use cached functions and createAsync. It handles deduplication, so you can just call the same cached function wherever in the tree and it will fetch only once.
Or use a global resource, wrapped in createRoot.