我一直在尝试在Expo中加载字体,但是我一直得到相同的错误。
这是我的代码:
我的Index.js如下所示:
import WelcomePage from "./Authentication/WelcomePage";
export default function Page() {
return (
<WelcomePage/>
);
}
而我的Welcomepage看起来是这样的:
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
这是我一直得到的错误:
警告:React检测到WelcomePage中Hooks调用的顺序发生了变化。如果不修复,这将导致错误和bug。了解更多信息,请阅读Hooks的规则:https://reactjs.org/link/rules-of-hooks
包括以下内容:
之前的渲染
下一个渲染
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
感谢 Mike 'Pomax' Kamermans
我已经弄清楚我应该先做一个 MCVE。这样我意识到问题不在于字体,而是关于我的
javascript windowForm().at(0)在同一个 const 中被调用。我还不确定原因,但是当我将它们分开时,就没有报错了。一旦我了解更多,我会编辑这篇帖子。向Mike致敬。