DEV Community

Discussion on: 5 Tips Every React Developer Should Know

Collapse
 
willaiem profile image
Damian Żygadło • Edited

In 99% cases - hooks.

You can check also this post, if you really want to know:
medium.com/javascript-scene/do-rea...

Yes, HOC can be used, but only in niche scenarios that you won't encounter super often.

Thread Thread
 
ruppysuppy profile image
Tapajyoti Bose

If you work on a large project not using an HOC for layout will be a huge pain. The connect function was indeed replaced with hooks, but you would still need the withRouter HOC for quite a few cases

We both have different viewpoints. So, let's agree to disagree :)

Thread Thread
 
raibtoffoletto profile image
Raí B. Toffoletto

Am I wrong in understanding that Everytime you use HOC those components (nav, footer, ...) will be mounted and remounted?? I think better layout way is router and lazy loading, right? Or as said Hooks and Context.

The beauty of react-router is to nest as many switches as you need. And I so far haven't found an use for withRouter since useHistory and other hooks are available.

Thread Thread
 
ruppysuppy profile image
Tapajyoti Bose • Edited

The purpose of a separate layout would be to keep the routing logic separate from the ui logic. But you are correct about the re-rendering of the components.

I have used useHistory for only navigation, so I don't have enough knowledge to comment on how it compares to withRouter

Thanks for your input :)