首页 > 解决方案 > 如何确保在 Expo/React Native 中的任何其他内容之前调用代码?

问题描述

我想在任何其他代码之前执行 SplashScreen.preventAutoHideAsync。

我已将它放在任何其他代码之前,包括希望在任何其他功能组件之前但在导入之后调用它

import * as SplashScreen from "expo-splash-screen";
... other imports ...

SplashScreen.preventAutoHideAsync().catch(() => {
  /* reloading the app might trigger some race conditions, ignore them */
});

...

export default function App() {
...
}

但是,我不确定imports 中是否有任何东西导致我的启动画面消失SplashScreen.hideAsync().catch(() => {});

我可以只使用require而不是import确保执行顺序吗?

标签: javascriptreact-nativeexpo

解决方案


推荐阅读