Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
frontend ruleP1universalStack: React
reactevent-handlersrenderingperformance
Pass handler references to event props, do not invoke them during render
Wiring a function that runs immediately (returning its call result) into onClick executes it on every render. Pass a reference or wrap in an arrow.
PR: hegnar-components · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetsx
| 1 | <button onClick={handlerFactory(id)}>Click</button> |
| 2 | // handlerFactory(id) runs on every render, not on click |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetsx
| 1 | <button onClick={() => handlerFactory(id)}>Click</button> |
| 2 | // or hoist a stable handler so it isn't recreated each render |
Explanation (EN)
Objašnjenje (HR)