Reputation: 1577
I've got this error
ERROR TypeError: React.useState is not a function. (In 'React.useState(false)', 'React.useState' is undefined)
I'm using these dependencies
"dependencies": {
"react": "16.13.1",
"react-dom": "16.13.1",
"react-native": "~0.63.3",
"expo": "~39.0.2",
"expo-splash-screen": "~0.6.2",
...
}
I thought Hooks are available from 16.8.0 and above. Isn't it? What's the problem?
EDIT
Here the snipper of code that causes the crash
import { Ionicons } from '@expo/vector-icons';
import * as Font from 'expo-font';
import * as SplashScreen from 'expo-splash-screen';
import * as React from 'react';
export default function useCachedResources() {
const [isLoadingComplete, setLoadingComplete] = React.useState(false);
// Load any resources or data that we need prior to rendering the app
React.useEffect(() => {
async function loadResourcesAndDataAsync() {
try {
SplashScreen.preventAutoHideAsync();
// Load fonts
await Font.loadAsync({
...Ionicons.font,
'space-mono': require('../assets/fonts/SpaceMono-Regular.ttf'),
});
} catch (e) {
// We might want to provide this error information to an error reporting service
console.warn(e);
} finally {
setLoadingComplete(true);
SplashScreen.hideAsync();
}
}
loadResourcesAndDataAsync();
}, []);
return isLoadingComplete;
}
Upvotes: 1
Views: 1953
Reputation: 458
See if this helps?
import React, { useState } from 'react';
const [isLoadingComplete, setLoadingComplete] = useState(false);
Upvotes: 1