Hydration mismatch when trying to reference slot element outside of JSX
My component has two optional props
leadingElement
and trailingElement
that expect a JSX element or fragment. I insert them like this:
When I try to reference these props outside of the JSX return, it results in a hydration mismatch:
Component works fine without this line. Code: https://pastebin.com/AjVSuhQMPastebin
import { createSignal, JSX, splitProps } from "solid-js";import { c...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
15 Replies
Component usage:
You should probably wrap the condition in the children wrapper
https://docs.solidjs.com/reference/component-apis/children#children
consider accepting components as opposed to elements if you’re okay with checking if they are passed or not
I used it like this:
still the same error
also,
<local.leadingComponent />
is valid jsxaccording to my type:
I can't use this syntax because element is already constructed
should I pass render function instead?
yes, that’s what i meant in the last reply
gonna try rn
thanks, it worked!
does it create overhead or it's fine?
in general, it’s best to avoid working with elements and instead prefer components
no overhead
so it will compile to the same code?
not the same code final output, but will get the same result
given you don’t call the component twice
can you explain this a little bit
a sec, let me point to an issue
https://github.com/solidjs/solid-start/issues/1568
https://github.com/solidjs/solid/issues/1977
Also
this is a bit unintuitive, but I'm starting to understand
thanks
layout won't change so it shouldn't be reactive
but I'm gonna add this as well