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 ruleP1stack specificStack: react
reactperformancereadabilityhooks
Hoist component-independent functions and values out of the component body
If a function or value inside a component doesn't reference props or state, define it at module scope so it isn't recreated on every render.
PR: vinify-frontend · org-mining-2026-06Created: Jun 17, 2026
Bad example
Old codetsx
| 1 | function Widget() { |
| 2 | const formatLabel = (v) => `Vintage ${v}`; |
| 3 | const options = ['a', 'b', 'c']; |
| 4 | return <List items={options.map(formatLabel)} />; |
| 5 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetsx
| 1 | const OPTIONS = ['a', 'b', 'c']; |
| 2 | const formatLabel = (vintage) => `Vintage ${vintage}`; |
| 3 |
|
| 4 | function Widget() { |
| 5 | return <List items={OPTIONS.map(formatLabel)} />; |
| 6 | } |
Explanation (EN)
Objašnjenje (HR)