I can see the data in console.log, but I couldn't pass it to render function with authenticated user information from firebase. Can anyone help please. I've tried many ways, when I use this.setState({..}) and use this.state.userItem in the return, but it tells me that the setState function is not defined. I've been stuck on this for two days. and this.state.userItem is not defined either and goes to code error.
`class AccInfo extends React.Component { state = { userItem: null }
componentDidMount(){
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
var db = firebase.firestore()
db.collection('user').doc(user.uid)
.get()
.then(snapshot => {
const userItem = snapshot.data()
console.log(userItem.name)
this.setState({userItem: userItem})
})
.catch(error => console.log(error))
} else {
}})
}
render() {
return( <div>
<p>{userItem.name}</p>//this is where I mess up
</div>
)
}
}
export default AccInfo;`