React Native AsyncStorage storing values other than strings

0
1206

Although you can only store strings, you can also stringify objects and arrays with JSON to store them, then parse them again after retrieving them.

This will only work properly with plain Object-instances or arrays, though, Objects inheriting from any prototypes might cause unexpected issues.

An example :

// Saves to storage as a JSON-string
AsyncStorage.setItem('key', JSON.stringify(false))

// Retrieves from storage as boolean
AsyncStorage.getItem('key', (value) => {
    JSON.parse(value) // boolean false
})