No.
React Native uses AsyncStorage
as its main data persistence solution. It makes use of its setItem
and getItem
methods to store/retrieve data.
All methods of AsyncStorage (see complete list) are asynchronous, and need to be await
ed to retrieve their values.
Example usage:
import { AsyncStorage } from 'react-native'; async componentDidMount() { const user = await AsyncStorage.getItem('user'); this.setState({ currentUser: JSON.parse(user) }); } storeUser = async (user) => { const userString = JSON.stringify(user); await AsyncStorage.setItem('user', userString); console.log('User succesfully saved.'); }
Keep in mind that setItem
will only allow values of type string
, so make sure to JSON.stringify
any objects that you want to store to AsyncStorage
, and to JSON.parse
any objects retrieved by getItem
.