I want to assign a JSON object to a state in react native.
this.state = {
card: null
}
_getCardDetails() {
getItem('userData').then(data => {
this.setState({
card: data.user.creditCard
})
})
}
render() {
const { card } = this.state
return (
<Text>{card}</Text>
)
}
i'm getting the JSON object from a axios call to my backend. But I can't assign that object to state in React Native.
Response from _getItem()
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7ImlkIjo4MzY5NDc5ODk5fSwiaWF0IjoxNTgwMzU1NjkyfQ._tYykbMtegpl58Poat0w2PsMUpnGFypqFd_7P2s6wQ8",
"next": true,
"user": {
"isProfileComplete": false,
"createdAt": "2020-01-28T11:42:53.413Z",
"_id": "5e302aa091741b14c0ef18bc",
"phone": 8369479899,
"creditCard": {
"createdAt": "2020-01-28T11:42:53.440Z",
"creditCardExpiry": "2021-01-28T11:42:53.440Z",
"_id": "5e302aa091741b14c0ef18bb",
"creditCardNo": 512723298971919,
"creditCardCVV": 381,
"__v": 0
},
"__v": 0
}
}
card.numberdoes not exist.cardis also not working, I'm gettingnullonly