What's the most idiomatic way of forwarding an onClick event handler?
Given a
Button
component that wraps a <button>
, what's the best way to forward the onClick
handler? Seems handlers can be functions or tuples. When passing the prop directly to the button,
the linter complains that props.onClick
is reactive, but handlers are not
This is how I'm doing it currently,
10 Replies
I use this method with no trouble, or linter errors, thus far, though I have no idea if it is the most idiomatic solution:
Is the suggestion code above processed by Solid's ESLint plugin? An error is reported when reproducing the above code on a file processed by Solid's ESLint plugin,
the error,
Linter error info: https://github.com/solidjs-community/eslint-plugin-solid/blob/main/docs/reactivity.md
hu
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
I initially thought it was a false positive bc the linter is quite aggressive
but in this case the linter is correct, if you don't wrap the prop in a function it will not re-assign it if the prop ever updates.
pretty unexpected behavior imo
event handlers are not reactive afaik
you know if this is mentioned anywhere in the old/new docs?
SolidJS
Solid is a purely reactive library. It was designed from the ground up with a reactive core. It's influenced by reactive principles developed by previous libraries.
https://github.com/solidjs-community/solid-primitives/tree/main/packages/props#combineProps works great for this
GitHub
solid-primitives/packages/props at main · solidjs-community/solid-p...
A library of high-quality primitives that extend SolidJS reactivity. - solidjs-community/solid-primitives
Yeah strangely it is - I don't know why I don't see the same error, am using plugin:solid/typescript