HNHacker News
TopNewBestAskShowJobs

pigcat

749 karma · joined May 3, 2021

submissionscomments
pigcat··on React best practices
I disagree with 4 as well

Maybe the author just used a poor example, but his useToggle is actually less readable to me.

The initial example with just useState is super obvious to understand what's going on in that component.

With his useToggle example, if I'm in this codebase I'm now asking myself - does toggle() fire some hidden side effect? Now I need to go check out the hook to make sure.

pigcat··on React best practices
I can't see any advantage of doing it this way

You are already deciding that this component will take one of iconProps/buttonProps/dropdownItemProps, so you've already decided what type of component it is. You might as well just call <Icon />, <Button />, or <Dropdown.Item /> from the parent component and have more readable code.

← PreviousPage 3 of 3