-3
I have the following functions in common.js
import AsyncStorage from '@react-native-async-storage/async-storage'
const getData = async () => {
try {
const jsonValue = await AsyncStorage.getItem('@storage_Key')
return jsonValue != null ? JSON.parse(jsonValue) : null;
} catch (e) {
// error reading value
}
}
const storeData = async (value) => {
try {
const jsonValue = JSON.stringify(value)
await AsyncStorage.setItem('@storage_Key', jsonValue)
} catch (e) {
// saving error
}
}
export { getData, storeData }
And I have the following functional component Auth.js:
import React, { useState } from 'react'
import axios from 'axios'
import { serverLogin, showError, storeData, getData } from '../common'
console.log(getData())
const initialState =
{
email: '',
password: '',
save: false
}
export default props => {
const [state, setState] = useState(initialState)
const signin = async () => {
try {
storeData(state)
const res = await axios.post(serverLogin, {
email: state.email,
password: state.password
})
props.onStoreToken(res.data.token)
} catch (e) {
showError(e)
}
}
return (
...
)
}
As you can see above, I put a.log (getData()) console to check the content saved in Asyncstorage, but I only get this strange return:
{"_U": 0, "_V": 0, "_W": null, "_X": null}
So I’ve researched this is related to a mistreatment with async/await, but I can’t pinpoint where part of the code. Can someone help me?