I've been trying to load fonts in Expo, but I keep getting the same error.
This is my code:
My Index.js looks like this:
import WelcomePage from "./Authentication/WelcomePage"; export default function Page() { return ( <WelcomePage/> ); }
And my Welcomepage looks like this:
import {Link, useRouter} from "expo-router"; import {windowForm} from "../Design/WindowForm"; import {Button} from "react-native-paper"; import Styles from "../Design/styles"; import Constants from "expo-constants"; import {Inter_900Black, useFonts} from "@expo-google-fonts/inter"; const WelcomePage = () => { const router = useRouter() let [fontsLoaded] = useFonts({ Inter_900Black, }); if (!fontsLoaded) { return null; } return( <View style={{width: windowForm().at(0), height:windowForm().at(1)}}> <Text style={{fontFamily:'Inter_900Black'}}> Hey </Text> </View> ) } export default WelcomePage
This is the error I keep getting:
Warning: React has detected that the order of Hooks calls in WelcomePage has changed. If not fixed, this will lead to errors and bugs. For more information, read the Rules of Hooks: https://reactjs.org/link/rules-of-hooks
Includes the following:
Previous rendering
Next rendering
Thanks to Mike 'Pomax' Kamermans
I've figured out I should do an MCVE first. This way I realized that the problem was not with the font, but with my
javascript windowForm().at(0)
being called in the same const.I'm not sure why yet, but when I separate them, there are no errors. I'll edit this post once I know more. Hats off to Mike.