React Handbook
devouringdetails.com·7w·
Discuss: Hacker News

How do you name props? Why are enum props good? What the hell is composability and why is it useful? Should you always use React?

If you’ve ever thought about these questions then you’re in the right place. I’m not preaching absolute truth but merely some personal preferences and understandings of what makes a good React component.

Contextual props

A common flaw I see in naming props for components is duplication of context.

Consider this example:

The props for controlling the dialog state also include the word "dialog". But in no way does this make it more clear what the props are doing. Omitting the duplication doesn’t lose meaning, but makes using the component more ergonomic because you have to type less.

Notice how the state is isDialogOpen yet the component takes a…

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help