In my React Native app, I want to store the token into AsyncStorage but when trying to do so, it throws the following warning.I went through many SO answers regarding this kind of issues but couldn't come up with a solution.
SignupScreen.js
import React from "react";
import { View } from "react-native";
import { AsyncStorage } from '@react-native-community/async-storage'
import PhoneInput from "react-native-phone-input";
import {
Button,
Text,
Form,
Item as FormItem,
Input,
Label,
} from 'native-base';
export default class Signup extends React.Component {
static navigationOptions = {
drawerLabel: "Signup",
};
constructor(props) {
super(props);
this.state = {
fname: "",
mobile: "",
};
}
setToken = async () => {
//This is where the warning is throws
await AsyncStorage.setItem('token', 'tokka').then(
val => {
if(val) this.props.navigation.navigate('Dashboard')
}
)
}
render() {
return (
<View style={{paddingTop: "40%"}}>
<Text style={{textAlign: "center",fontSize: 40}}>OnTask</Text>
<Text style={{fontSize: 20,textAlign: "center"}}>Signup</Text>
<Form>
<FormItem>
<Label>First Name</Label>
<Input />
</FormItem>
<Label style={{marginTop: "3%",marginLeft: "4%"}}>Mobile Number</Label>
<PhoneInput
ref="phone"
style={{
height: 50,
padding: 10,
width: 300,
marginLeft: "2%",
marginBottom: "5%",
borderRadius: 10
}}
onChangePhoneNumber={ number => this.setState({mobile: number})}
/>
<Button full primary onPress={() => this.setToken()}>
<Text> Sign Up </Text>
</Button>
</Form>
</View>
);
}
}
