I am using query-string to pass some parameters and render the below component
import React, { Component } from "react";
class Show extends Component {
constructor(props,context) {
super(props,context);
this.state = {
name: ''
};
console.log(this);
}
render() {
return (
<div>
<h4>Hi {this.props.match.params.name} </h4>
<p></p>
{this.props.match.params.name ? <b>ID: {this.props.match.params.name}</b> : }
</div>
);
}
}
export default Show;
The route is like below :
<Route path='/show/:name?' component={Show} />
But this always results in undefined name and I see only Hi not the name .I use the below versions .
"react-dom": "^16.13.0",
"react-router-dom": "^5.1.2",
"query-string": "^6.11.1"
Not sure where I am making a mistake .Any help is appreciated.