startasync in apploading doesnt fire

  1. SDK Version: 40.0.0
  2. Platform: Android

Noob here. startAsync prop in AppLoading doesnt seem to execute unless I pass “f()” instead of “f”. Im using this guide Waiting for Asynchronous Load in React Native | by Ben Aron Davis | Dev Genius | Medium

const [loading, setLoading] = useState (false)

const f = () => {
return async () => {
try {
console.log (‘something’)
const userStored = AsyncStorage.getItem(‘userStored’)
} catch (e) {
console.log(e)
}}}

if (!loading) {
return (
<AppLoading startAsync={f()} onFinish={() => setLoading(true)} onError={(e) => console.error(e)} />
)} else {
if (userStored){
return (

)} else {
return (

)}

Got it working. AppLoading now executes an asynchronous task before loading the rest of the app. This is the part I made changes to:

const f = async () => {
const userStored = await AsyncStorage.getItem(‘userStored’)
}

if (!loading) {
return (
<AppLoading startAsync={f} onFinish={() => setLoading(true)} onError={(e) => console.error(e)} />
)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.