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).
Keep reusable hooks out of page/view folders
Place custom hooks in a shared hooks directory; reserve view folders for components and their styles.
Bad example
| 1 | // views/orders/hooks/useFetchOrders.ts |
| 2 | export function useFetchOrders() { |
| 3 | const [orders, setOrders] = useState<Order[]>([]); |
| 4 | useEffect(() => { |
| 5 | fetchOrders().then(setOrders); |
| 6 | }, []); |
| 7 | return orders; |
| 8 | } |
| 9 |
|
| 10 | // views/orders/OrdersView.tsx |
| 11 | import { useFetchOrders } from './hooks/useFetchOrders'; |
Explanation (EN)
The hook lives inside the view folder, mixing reusable logic with page-specific component code. Any other view that needs the same data-fetching logic must reach into this view's internals to reuse it.
Objašnjenje (HR)
Hook se nalazi unutar view foldera, miješajući logiku za ponovnu upotrebu s kodom specifičnim za stranicu. Bilo koji drugi view kojem treba ista logika dohvaćanja podataka mora posezati u unutrašnjost ovog viewa da bi je iskoristio.
Good example
| 1 | // utils/hooks/useFetchOrders.ts |
| 2 | export function useFetchOrders() { |
| 3 | const [orders, setOrders] = useState<Order[]>([]); |
| 4 | useEffect(() => { |
| 5 | fetchOrders().then(setOrders); |
| 6 | }, []); |
| 7 | return orders; |
| 8 | } |
| 9 |
|
| 10 | // views/orders/OrdersView.tsx |
| 11 | import { useFetchOrders } from 'utils/hooks/useFetchOrders'; |
Explanation (EN)
The hook lives in the shared hooks directory, so it can be discovered and reused by any view. The view folder stays focused on components and their styles, keeping responsibilities clearly separated.
Objašnjenje (HR)
Hook se nalazi u zajedničkom hooks direktoriju, pa ga bilo koji view može pronaći i ponovno upotrijebiti. View folder ostaje fokusiran na komponente i njihove stilove, čime su odgovornosti jasno odvojene.
Notes (EN)
View/page folders are for non-reusable, page-specific UI. Hooks, utilities, and services that could be shared belong in their dedicated top-level directories.
Bilješke (HR)
View/page folderi su za UI specifičan za stranicu koji se ne ponovno koristi. Hookovi, pomoćne funkcije i servisi koji bi se mogli dijeliti pripadaju u svoje namjenske direktorije najviše razine.