Weird Context Behaviour
I'm currently setting up a tip tap editor with solid and wanted to create a context to pass the editor around the components.
I have a root component that creates the editor and then multiple sub components that want to consume the editor.
4 Replies
However when I render
<EditorRoot>
<EditorBubble ...>
</EditorRoot>
I get "useEditor must be used within an EditorProvider", which I defined in the context.ts, but I don't get why
You're destructing
children
out of props, which is causing EditorBubble
to be evaluated before EditorProvider
Also you're spreading props
into useEditor
which will do the same thing
Step 1 would be to use splitProps
to separate the editor props from children
and class(Name)
safely
Step 2 you'd probably want to make useEditor
take an accessor so that it can read the editor props reactivelyAlright, using split props fixed it.
Why is that tho? Is a page evaluated from bottom to top / children to parents in Solid? Which now that I think about would make sense
Kinda - the way i'd describe it is that components evaluate top to bottom, and then as each parent component renders its children the html elements are constructed from bottom to top
The important thing is that
children
in most cases is implemented as get children() {}
, so if you do props.children
or spread outside of the component body the children will be evaluated before the parents