Last active
October 26, 2019 14:41
-
-
Save bpander/3f4711882badc2a203bd5490c74bd2d6 to your computer and use it in GitHub Desktop.
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
const [data, setData] = useState(); | |
useEffect(() => { | |
const load = async () => { | |
const r = await asyncFn(userId); | |
setData(r); | |
}; | |
load(); | |
}); | |
useEffect(() => { | |
handleData(data); | |
}, [data]); | |
// usage | |
const userId = 'lkj'; | |
const loaders = { | |
phones: useAsync( | |
useCallback( | |
() => method === ValidationMethod.TwoFactor && getUserPhones(userId), | |
[userId, method], | |
), | |
useCallback(result => { | |
if (result.error) { | |
props.navigation.navigate('somewhere else'); | |
return; | |
} | |
}, [props.navigation]), | |
[], // optional initial value | |
), | |
}; | |
const isLoading = Object.values(loaders).some(loader => loader.isLoading); | |
const userPhones = loaders.phones.value; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment