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 ruleP2universalStack: react
reacteventsreadabilityhandlers
Prefer dedicated handlers over data-attribute action dispatch
Instead of encoding an action in a data attribute and branching with if/else, write one explicit handler per action.
PR: hegnar-forum-web · org-mining-hist-2026-06Created: Jun 20, 2026
Bad example
Old codetsx
| 1 | const handleClick = (e) => { |
| 2 | if (e.currentTarget.dataset.action === 'up') upvote(); |
| 3 | else downvote(); |
| 4 | }; |
| 5 | <button data-action="up" onClick={handleClick} /> |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetsx
| 1 | const handleUpvoteClick = () => upvote(); |
| 2 | const handleDownvoteClick = () => downvote(); |
| 3 | <button onClick={handleUpvoteClick} /> |
Explanation (EN)
Objašnjenje (HR)