Reputation: 25
I'm trying to get everything from JSON with Axios get, all works except boolean value, is not parsing to String (Im adding the current state.toString() but not working. Or is there other way to show it ? in backend api "isInstructed":true,
const { id } = this.props.match.params
axios.get(`/visitors/${id}`)
.then(res => {
this.setState({ visitors: res.data });
}
The render
return (
<h4>Is instructed? </h4>{this.state.visitors.isInstructed.toString()}
Upvotes: 1
Views: 591
Reputation: 1
Inside your then callback's call, right in the body, try to console.log your res to see what you can retrieve or if it gets some call's errors
Upvotes: 0
Reputation: 4352
Maybe the initial value for this.state.visitors
is undefined
or null
.
Try
return (
<h4>Is instructed? </h4>
{
this.state.visitors && typeof this.state.visitors.isInstructed !== undefined ?
this.state.visitors.isInstructed.toString() :
null
}
Upvotes: 1