I am trying to get the body of my api request in reactJS. It returns the right 'body' on the submitHandler function but returns [object Object] when called on a different component. Below is my code:
Login (SubmitHandler):
submitHandler(event) {
event.preventDefault()
axios
.post("http://localhost:8000/rest-auth/login/", this.state)
.then(res => {
if (res.data){
sessionStorage.setItem('data', res)
this.setState({redirect:true})
}
console.log(res.data)
})
.catch(err => {
this.setState({
error: true, errorMessage: err
})
// console.log(this.state.errorMessage)
})
}
profile(componentDidMount):
componentDidMount()
{
if(sessionStorage.getItem('data')){
let user_data = sessionStorage.getItem('data')
console.log(user_data)
}
else {
this.setState({
redirect:true
})
}
}
componentDidMount returns [object Object] instead of an api body response.