withRouter vs react-router-dom hooks (useHistory, useLocation, useMatch)

Viewed 3258

Sometimes I use withRouter to wrap my component and use history, location from props, sometimes I use useHistory(), useLocation(). I don't know the advantages or disadvantages of these two ways to use.

1 Answers

What you're asking is not specific to react-router-dom, you're asking about the differences between using HOC pattern vs using hooks in React which is in a nutshell a decision between these values in projects:

  • Readability
  • Reusability
  • Customisation and usage
  • Debugging
  • Testability
  • Performance

which you can know more about them in these links:

https://medium.com/simply/comparison-hocs-vs-render-props-vs-hooks-55f9ffcd5dc6

https://www.robinwieruch.de/react-hooks-higher-order-components

https://medium.com/javascript-scene/do-react-hooks-replace-higher-order-components-hocs-7ae4a08b7b58#:~:text=For%20broadly%2Dused%20cross%2Dcutting,UI%20code%20in%20your%20app.

Related