Choose variable, function, and type names that clearly communicate their purpose, source, and context. Names should be self-documenting and avoid ambiguity or conflicts with existing identifiers.
Key principles:
formItemName
instead of defaultName
, ButtonClassNamesType
instead of generic Partial<Record<...>>
)cls
for classnames utility vs classNames
for semantic props)iconPosition
consistently rather than mixing iconPos
and iconPosition
)Example:
// ❌ Generic and potentially confusing
const defaultName = useId();
classNames?: Partial<Record<ButtonSemanticName, string>>;
// ✅ Semantic and descriptive
const randomId = useId();
const defaultName = formItemName || randomId;
classNames?: ButtonClassNamesType;
// ❌ Naming conflict
import classNames from 'classnames';
// ... later in code
<div classNames={props.classNames} />
// ✅ Clear distinction
import cls from 'classnames';
// ... later in code
<div className={cls(...)} classNames={props.classNames} />
Enter the URL of a public GitHub repository