Skip to content

Instantly share code, notes, and snippets.

@joduplessis
Last active September 7, 2017 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joduplessis/4b6406f3e5962683e158cf249b791284 to your computer and use it in GitHub Desktop.
Save joduplessis/4b6406f3e5962683e158cf249b791284 to your computer and use it in GitHub Desktop.
Example of handling React Native's AsyncStorage with Redux actions.
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