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