简体   繁体   中英

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

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM