データの格納および取得に次のコードを使用しています。しかし、それは私が望むように働いていません。ReactネイティブAsyncStorageがデータを取得しない
async setDataFromApi(token, json) {
const {goBack} = this.props.navigation; // Navigation
let iext_inf = {
token: token,
userid: json.data.id,
username: json.data.username,
image: json.data.profile_picture,
};
console.log(iext_inf);
try {
await AsyncStorage.setItem('iext_inf', JSON.stringify(iext_inf)); // Stuck here
goBack();
} catch (error) {
console.log("Error");
}
}
をデータ取得::私は間違って何をやっている
async componentWillMount() {
try {
const value = await AsyncStorage.getItem("iext_inf"); //Stuck here
console.log(value);
if (value !== null){
this.setState({
data : value
})
}
if (this.state.data !== null) {
this.props.navigation.navigate('Home', {'access_token': value});
}
} catch (error) {
console.log(error);
}
}
をデータの設定
?私は単一のデータを追加して検索しようとしましたが、それは何らかの理由で機能しました。今はそうではありません。 ありがとうございます。
は、asyncstorageに渡すデータは有効ですか?あなたは何かエラーが発生しています –
@PanagiotisVrs私はその有効だと思います。エラーは発生しません。 –
AsyncStorage.getItem( 'iext_inf'、(err、result)=> {})のようなコールバックを試すことができます –