I use reach router like this below before and it works fine
.....
<Router>
<ComponentA path="/:id">
<ComponentB path="/">
<Router>
....
I decided to refactor my code with context, and the code is refactored to something like this:
<GlobalContextProvider>
<GlobalContext.Consumer>
{( context) =>{
return(
.....
<Router>
<ComponentA path="/:id">
<ComponentB path="/">
<Router>
....
}
After the refactor, the ComponentA is not working properly, as the url param prop id is not passed
In the ComponentA.js , test like this:
componentDidMount() {
const { id } = this.props;
console.log(id); // return undefined
}
Also when I console.log(this.props)
, it returns the same result as this.context
Can someone help me understand why this is happening? How to refactor with context properly?
Thanks a lot