Replies: 1 comment
-
|
Both behaviors are expected and intentional — they come from two different merging mechanisms. Case 1: <button classList={{ 'bg-color': true }} {...props}></button>SolidJS compiles JSX spreads through You can read more in the SolidJS docs on mergeProps — the key line is: "mergeProps merges potentially reactive objects without losing reactivity, giving special treatment to class, classList, style, and ref." Case 2: spreading a plain object literal → override (not merge) const borderColor = { classList: { 'border-color': true } };
<Button classList={{ 'text-color': true }} {...borderColor}>Here you're spreading a plain non-reactive JS object, not a SolidJS props object. The JSX compiler treats this as a standard JS object spread — Is it reliable? Yes for case 1. The merge behavior on Can you use merge without the parent→child pattern? Yes — call const merged = mergeProps(
{ classList: { 'text-color': true } },
borderColor
);
<Button {...merged}>This gives you the same merge semantics anywhere, not just in component bodies. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I got a confusing case where
classListdoes not override but merge classes when passed from parent to child.That
Buttongets both classes applied.Is it something expected and where I can read more on how and why?
I find it useful, but is it reliable?
Is it possible to use it without the parent->child passed props?
For example the following does not work
Example playground: https://stackblitz.com/edit/github-te6jt77k?file=src%2FApp.tsx
Beta Was this translation helpful? Give feedback.
All reactions