Should I disable `solid/reactivity` linter warning in this case?
I frequently run into this warning with event handlers. Here's an example:
Is there a problem with this code? If so, what's wrong with it? Otherwise, should I disable this warning in situations like this one?
Is there a problem with this code? If so, what's wrong with it? Otherwise, should I disable this warning in situations like this one?
12 Replies
Try
The parameter types let the linting rule know that it's not a regular function but an event handler destined to be used in Solid's JSX.
What if I need to pass something else to the handler other than the event?
You create the event handler where the "something else" will be included in the eventhandler's closure. That's exactly what happens with
props.something
.Right, but then I wouldn't be able to use
InputEventHandler
.Look at the example.
handleInput
uses props.something
and it's still an InputEventHandler
.Let me give a concrete example.
Could I define
handleInput
outside the jsx and still be able to access item
without running into the linter warning?I would try this:
Or perhaps more simply:
Oh, I hadn't thought of putting the event handler outside of the component function. Is this a common idiom?
I wouldn't say so, it's just something I naturally arrived at because I'm not fond of anonymous inline functions,
During the first beta:
https://github.com/peerreynders/solid-start-todomvc-kcd-v2/blob/d3ba9953c83f3777b66fda375bc588e139ca8452/src/routes/%5B...todos%5D.tsx#L848-L913
Though for all I know it now triggers linter warnings 🤷
GitHub
solid-start-todomvc-kcd-v2/src/routes/[...todos].tsx at d3ba9953c83...
TodoMVC inspired by kentcdodds/remix-todomvc implemented with SolidStart - peerreynders/solid-start-todomvc-kcd-v2
I see. Would you say then that, of the people that use
eslint-plugin-solid
, most just disable the warning?Not that I'm aware of
Okay, thanks for your help!