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
reactrenderperformancepurity
Do not sort or mutate data inside the render method
Compute sorted or derived data outside render (memoized or upstream) instead of sorting on every render pass.
PR: hegnar-web · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codejsx
| 1 | render() { |
| 2 | const sorted = this.props.items.sort(byPrice); |
| 3 | return <List items={sorted} />; |
| 4 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codejsx
| 1 | const sorted = useMemo(() => [...items].sort(byPrice), [items]); |
| 2 | return <List items={sorted} />; |
Explanation (EN)
Objašnjenje (HR)