Skip to content

Commit 5bc7c08

Browse files
Update src/routes/reference/jsx-attributes/classlist.mdx
Co-authored-by: Sarah <hello@sarahgerrard.me>
1 parent f13bf1e commit 5bc7c08

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

src/routes/reference/jsx-attributes/classlist.mdx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ setClasses((c) => ({ ...c, active: true }))
4848
<div classList={classes()} />
4949
```
5050

51-
It's also possible, but dangerous, to mix `class` and `classList`. The main safe situation is when `class` is set to a static string (or nothing), and `classList` is reactive (`class` could also be set to a static computed value as in `class={baseClass()}`, but then it should appear before any classList pseudo-attributes). If both `class` and `classList` are reactive, you can get unexpected behavior: when the `class` value changes, Solid sets the entire `class` attribute, so it will overwrite any toggles made by `classList`.
51+
While possible, mixing `class` and `classList` in Solid can lead to unexpected behavior.
52+
The safest approach is to use a static string (or nothing) for `class` and keep `classList` reactive.
53+
You can also use a static computed value for class, such as `class={baseClass()}`, however you must make sure it comes before any `classList` pseudo-attributes.
54+
If both `class` and `classList` are reactive, changes to `class` will overwrite the entire `class` attribute, potentially undoing any updates made by `classList`.
5255

5356
Because classList is a compile-time pseudo-attribute, it does not work in a prop spread like `<div {...props} />` or in `<Dynamic>`.

0 commit comments

Comments
 (0)