Last active
February 16, 2021 13:01
-
-
Save Leechael/e2f4aa67d76080615d3faee3245bef25 to your computer and use it in GitHub Desktop.
one-time restore initial from async func.
This file contains hidden or 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 { atom } from "jotai"; | |
import AsyncStorage from "@react-native-community/async-storage"; | |
const jwtTokenAtom = atom<string, string>("", (_, set, value) => { | |
set(jwtTokenAtom, value); | |
AsyncStorage.setItem("jwt_token", value); | |
}); | |
jwtTokenAtom.onMount = (set) => { | |
(async () => { | |
const value = await AsyncStorage.getItem("jwt_token"); | |
if (value) { | |
set(value); | |
} | |
})(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment