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).
Prefer descriptive names over generic verbs in effects
Avoid generic function names like 'run' or 'start' inside useEffect; use names that describe the specific action.
Bad example
| 1 | useEffect(() => { |
| 2 | const run = async () => { |
| 3 | const response = await api.get('/users'); |
| 4 | setUsers(response.data); |
| 5 | }; |
| 6 |
|
| 7 | run(); |
| 8 | }, []); |
Explanation (EN)
The name 'run' is generic and fails to describe what the function actually does. It forces the reader to parse the function body to understand the intent.
Objašnjenje (HR)
Ime 'run' je preopćenito i ne opisuje što funkcija zapravo radi. Tjera čitatelja da analizira tijelo funkcije kako bi razumio namjeru.
Good example
| 1 | useEffect(() => { |
| 2 | const fetchUsers = async () => { |
| 3 | const response = await api.get('/users'); |
| 4 | setUsers(response.data); |
| 5 | }; |
| 6 |
|
| 7 | fetchUsers(); |
| 8 | }, []); |
Explanation (EN)
The name 'fetchUsers' clearly describes the specific action (fetching data), making the code self-documenting and easier to scan.
Objašnjenje (HR)
Ime 'fetchUsers' jasno opisuje specifičnu radnju (dohvaćanje podataka), čineći kod lakšim za čitanje i samodokumentiranim.