You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use Context to inject some data globally, and I optimize the access to children according to the examples given in the tutorial, that is, using the children utility function to wrap props.children. However, the child components always access the initialValue of createContext through useContext, instead of the data I provide through Provider.
Please comment out this IS NOT WORK code, 16-19 lines.
Than comment in IS WORK code, 22-24 lines.
Butten Render -2, this is provide by Context.Provider.
Expected behavior
I hope that when using the children utility function, the child components will not be initialized in advance, causing useContext to be unable to get the provided value.
Screenshots or Videos
No response
Platform
OS: Windows
Browser: Chrome
Additional context
No response
The text was updated successfully, but these errors were encountered:
See this solidjs/solid#1926
TLDR: using children changes the context on which things run, so children isn't evaluated inside the context as you may expect.
See this solidjs/solid#1926 TLDR: using children changes the context on which things run, so children isn't evaluated inside the context as you may expect.
very grateful for your answer, I spent several hours troubleshooting this issue. Perhaps we could add explanations to the documentation or tutorials to explain this hidden behavior.
Yeah docs could be clearer here with a context example. We say that it resolves the children so they can be introspected, but for those not familiar with that Solid doesn't use a VDOM so resolved means do the rendering it isn't obvious this can happen. We use conditional rendering as an example but not context. https://www.solidjs.com/docs/latest/api#children
Describe the bug
I use Context to inject some data globally, and I optimize the access to children according to the examples given in the tutorial, that is, using the children utility function to wrap
props.children
. However, the child components always access theinitialValue
ofcreateContext
throughuseContext
, instead of the data I provide through Provider.Your Example Website or App
https://playground.solidjs.com/anonymous/29fa1b7c-efd7-4f32-a6f7-1a37c22b047c
Steps to Reproduce the Bug or Issue
-1
, this isinitialValue
.IS NOT WORK
code, 16-19 lines.IS WORK
code, 22-24 lines.-2
, this is provide byContext.Provider
.Expected behavior
I hope that when using the
children
utility function, the child components will not be initialized in advance, causinguseContext
to be unable to get the provided value.Screenshots or Videos
No response
Platform
Additional context
No response
The text was updated successfully, but these errors were encountered: