I'm building a mobile app with React-Native and I'm using Firebase for it. I want to set push-notification and I did almost everything. My push notification works well. Now, I want to get all devices' token when users open the app. Actually I get and see device token on console.log using PushNotification.configure() but I try to get it for using in a function to save in Firestore then I got "this.setState()is not a function" or if I use asycn-await for my function then I get "token is read-only" errors. Here is my componentDidMount function:
componentDidMount() {
let tokenId = "";
this.props.GetProfileData(this.props.CustomerID, () => { }, () => { });
PushNotification.configure({
onRegister: function(token) {
console.log( 'TOKEN:', token );
tokenId = token;
//this.setState({token:token});
console.log( 'TOKEN:', tokenId.token );
},
});
console.log("HELLOOOOOO",tokenId);
this.props.UpdateProfileInfo(this.props.CustomerID,this.state.token,
()=>{
this.setState({
loading:false
})
},
()=>{
alert("error");
});
//console.log("READONLY",this.state.token);
}
I want to use user token in my UpdateProfileInfo() function to save it in firestore. And in my code tokenId is null, cannot assign token into my tokenId.
You can see my terminal and errors in screenshots and My error screen:
