I want to use the useRouteMatch
hook inside a class-based component in React because it simplifies passing parameter to component. Using this hook inside class component throws error. What is the equivalent of this hook to use in a React class?
You could use withRouter
HOC, and then there will be match
object in wrapped component props:
import React from 'react';
import {withRouter} from 'react-router-dom';
class SomeClassComponent extends React.Component {
render(){
console.log(this.props.match) // match object
return(<span />)
}
}
export default withRouter(SomeClassComponent)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With