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:
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
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.