constructor() {
super();
this.state = {
idnum: this.props.match.params.id,
pokemon: [],
imgurl: '',
abilities: [],
types: []
};
this.clickHandler = this.clickHandler.bind(this);
};
clickHandler(e) {
this.setState({
idnum: this.props.match.params.id
})
console.log("passed" , this.props.match.params.id)
}
I am trying to store this.props.match.params.id which is a id number passed in as a prop into one of my states in React.js this.props.match.params.id works in my componentWillMount function that uses this id number to call a specific data from an API, but it gives me that match is undefined when I try to store it in my state.
I need this to work so that I can make the page re-render when Linking to the page with previous Id number by doing
<Link to={{ pathname: '/details/' + (parseInt(this.props.match.params.id) - 1) }}><Button onClick = {this.clickHandler }>Prev</Button></Link>
What is the way to store my this.props.match.params.id into my state?