component-props-naming-and-structure
Installation
SKILL.md
Summary
Component props should feel like standard HTML Attributes.
- Naming: Use nouns or adjectives (
disabled,open,value). Avoid verb prefixes likeis/hasunless they are standard (likeisOpenin some libraries, but standard HTML usesopen). - Structure: Pass Primitive types (string, number, boolean) whenever possible, rather than passing large, complex Objects.
Rationale
- HTML Consistency:
disabled,checked,hidden,readonlyare standard attribute names. UsingisDisabledcreates a cognitive mismatch with the platform. - Decoupling: Accepting
userId(string) is loosely coupled. AcceptingUser(object) couples the component to the entire User shape, making it harder to reuse or mock. - Optimization: Primitives are easier for frameworks (Vue/React) to diff than deep objects.
Guidance
- Naming:
- Boolean Props:
disabled,checked,visible,open,loading. (AvoidisDisabled). - Event Props:
on[Event](React) or[event](Vue). e.g.,onSubmit,onChange.
- Boolean Props:
- Primitive Preference:
- Bad:
props: { user: UserObject } - Good:
props: { userId: string, userName: string, avatarUrl: string } - Exception: If a component is explicitly designed to render a specific domain entity (e.g.,
UserCard), passing the object is acceptable, but consider accepting a narrowed interface.
- Bad: