Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Do not keep empty callbacks to satisfy component APIs
If a callback does nothing, remove it and make the receiving prop optional instead of passing no-op handlers around.
Bad example
| 1 | const handleOpen = useCallback(() => {}, []); |
| 2 |
|
| 3 | return ( |
| 4 | <WrapperComponent |
| 5 | open={open} |
| 6 | onOpen={handleOpen} |
| 7 | onClose={handleClose} |
| 8 | /> |
| 9 | ); |
Explanation (EN)
The callback exists only to satisfy the prop contract. It adds noise and hides the fact that opening has no behavior.
Objašnjenje (HR)
Callback postoji samo da zadovolji prop contract. Dodaje sum i skriva cinjenicu da otvaranje nema nikakvo ponasanje.
Good example
| 1 | interface WrapperComponentProps { |
| 2 | open: boolean; |
| 3 | onClose: () => void; |
| 4 | onOpen?: () => void; |
| 5 | } |
| 6 |
|
| 7 | return <WrapperComponent open={open} onClose={handleClose} />; |
Explanation (EN)
The API expresses the real requirement: opening is optional. Call sites stay clean and intent is obvious.
Objašnjenje (HR)
API izrazava stvarni zahtjev: otvaranje je opcionalno. Mjesta koristenja ostaju cista i namjera je jasna.
Exceptions / Tradeoffs (EN)
A no-op is acceptable only when integrating with a third-party API that strictly requires a callable and cannot be wrapped locally.
Iznimke / Tradeoffi (HR)
No-op je prihvatljiv samo kod integracije s third-party API-jem koji strogo zahtijeva callable i ne moze se lokalno omotati.