React vs Solid wrt contexts
Lets say I have a component.
In BarComponent I have
The problem here. Is that react follows a top to bottom strategy and will render out the components following the hierarchy. So FooProvider gets run first and the context is available.
Whereas with Solid, the BarComponent is then run first and then finds the context to be empty. Is there any way to work around this? I either want the BarComponent not be run: Or to delay it until the context is available. Are there any solutions here? Thanks
Whereas with Solid, the BarComponent is then run first and then finds the context to be empty. Is there any way to work around this? I either want the BarComponent not be run: Or to delay it until the context is available. Are there any solutions here? Thanks
10 Replies
I think I have a possible solution to side step this whole issue. Will try tomorrow.
If you mean that ctx may be undefined.
Make a
Now ctx is infered without undefined
Thanks for the reply. But that already exists.
Are passing async data to the context or why is it undefined in the first render? It shouldn’t
No, no external data is being requested at all.
You are missing the context 😄
https://github.com/paulm17/mantinesolid/blob/main/packages/%40mantine/core/src/component/Card/Card.tsx#L118
Due to this line.
When Card is loaded. CardSection
from card.tsx and moving it to index.ts and hopefully this side steps the issue. I found this method late last night.
immediately
fires.
And because it fires, this line is then executed:
https://github.com/paulm17/mantinesolid/blob/main/packages/%40mantine/core/src/component/Card/CardSection/CardSection.tsx#L46
Before this line:
https://github.com/paulm17/mantinesolid/blob/main/packages/%40mantine/core/src/component/Card/Card.tsx#L108
Hope that clarifies things.
As I said above. React follows a different method of loading in components to Solid.
That said. I'm about to refactor things a little by removing
from card.tsx and moving it to index.ts and hopefully this side steps the issue. I found this method late last night.
I’d think resolving the children outside the context is probably the problem
I guess if you move that inside a context provider i should work
Unfortunately I don't think that's going to work. This pattern is used in many other components. I'm thankfully tacking a really simple use case. If I resolve this component, then I resolve all of them.
I'm now using a store instead of a context and have managed to almost circumvent the issue.
But reverting the code to show the issue completely:

I put init right at the top of both components. So card starts to run but does not complete. The provider is not available when cardSection runs as well. 🤷♂️
*
Could have sworn CardSection started before 😅 ...Finally!

