Last active
September 7, 2017 08:29
-
-
Save joduplessis/4b6406f3e5962683e158cf249b791284 to your computer and use it in GitHub Desktop.
Example of handling React Native's AsyncStorage with Redux actions.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { AsyncStorage } from 'react-native'; | |
export const actionMethod = () => { | |
return (dispatch, getState) => { | |
(async () => { | |
try { | |
const value = await AsyncStorage.setItem('@YourStore:key', '12345'); | |
if (value !== null) { | |
// Value of the stored token | |
} else { | |
// Dispatch an error code, something has gone wrong with the AsyncStorage | |
dispatch(anotherAction()); | |
} | |
} catch (error) { | |
dispatch(throwError('Whoops, there has been an error.')); | |
} | |
})(); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment