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).
Name the props interface `Props` for single-component files
Use a plain `Props` name for the props interface when a file defines one component; reserve `ComponentNameProps` for exported library types.
Bad example
| 1 | interface UserCardProps { |
| 2 | name: string; |
| 3 | } |
| 4 |
|
| 5 | export default function UserCard({ name }: UserCardProps) { |
| 6 | return <span>{name}</span>; |
| 7 | } |
Explanation (EN)
The `UserCard` prefix is redundant noise when there's only one component in the file and the type isn't part of a public API.
Objašnjenje (HR)
Prefiks `UserCard` je suvisan sum kad je u datoteci samo jedna komponenta i tip nije dio javnog API-ja.
Good example
| 1 | interface Props { |
| 2 | name: string; |
| 3 | } |
| 4 |
|
| 5 | export default function UserCard({ name }: Props) { |
| 6 | return <span>{name}</span>; |
| 7 | } |
Explanation (EN)
`Props` is unambiguous within a single-component file and keeps the type concise.
Objašnjenje (HR)
`Props` je nedvosmislen unutar datoteke s jednom komponentom i drzi tip sazetim.
Exceptions / Tradeoffs (EN)
Use a descriptive `ComponentNameProps` name when the props type is exported from a library or referenced by name across files.
Iznimke / Tradeoffi (HR)
Koristi opisno ime `ComponentNameProps` kad se tip propova izvozi iz biblioteke ili se referencira po imenu kroz vise datoteka.