Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/eslint-plugin-solid/src/rules/reactivity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -850,12 +850,14 @@ export default createRule<Options, MessageIds>({
if (node.type === "JSXExpressionContainer") {
if (
node.parent?.type === "JSXAttribute" &&
/^on[:A-Z]/.test(sourceCode.getText(node.parent.name)) &&
sourceCode.getText(node.parent.name).startsWith("on") &&
node.parent.parent?.type === "JSXOpeningElement" &&
node.parent.parent.name.type === "JSXIdentifier" &&
isDOMElementName(node.parent.parent.name.name)
) {
// Expect a function if the attribute is like onClick={} or on:click={}. From the docs:
// Expect a function if the attribute is like onClick={}, onclick={}, on:click={}, or
// custom events such as on-click={}.
// From the docs:
// Events are never rebound and the bindings are not reactive, as it is expensive to
// attach and detach listeners. Since event handlers are called like any other function
// each time an event fires, there is no need for reactivity; simply shortcut your handler
Expand Down
7 changes: 6 additions & 1 deletion test/valid/reactivity/on/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { createSignal, createEffect, on } from "solid-js";
const App = () => {
const [a, setA] = createSignal(1);
const [b, setB] = createSignal(1);
const [c, setC] = createSignal(1);

createEffect(
on(
Expand All @@ -19,7 +20,11 @@ const App = () => {
return (
<>
<button onClick={() => setA(a() + 1)}>Increment A</button>
<button onClick={() => setB(b() + 1)}>Increment B</button>
<button on:click={() => setB(b() + 1)}>Increment B</button>
<button on-click={() => setC(c() + 1)}>Increment C</button>
<button onClick={async () => setA(a() + 1)}>Async Increment A</button>
<button on:click={async () => setB(b() + 1)}>Async Increment B</button>
<button on-click={async () => setC(c() + 1)}>Async Increment C</button>
</>
);
};
Expand Down