React native 如何显示反应本机延迟的组件?

React native 如何显示反应本机延迟的组件?,react-native,React Native,我有以下内容,旨在向用户表明应用程序正在加载: function LoadingIndicatorView() { return ( <View> <ActivityIndicator color='#009b88' size='large' /> </View> ) } 函数加载指示器视图(){ 返回( ) } 5秒钟后,我希望“请稍候…”显示在活动指示灯下。如何操作?您可以尝试以下操作: fu

我有以下内容,旨在向用户表明应用程序正在加载:

function LoadingIndicatorView() {
    return (
      <View>
        <ActivityIndicator color='#009b88' size='large' />
      </View>
    )
  }
函数加载指示器视图(){
返回(
)
}

5秒钟后,我希望
“请稍候…”
显示在
活动指示灯下。如何操作?

您可以尝试以下操作:

function LoadingIndicatorView() {
    const [isLoading , seIsLoading] = React.useState(true);

    React.useEffect(()=>{
       const timeout = setTimeout(() => {
         seIsLoading (false);
       }, 5000);

       return () => { 
         clearTimeout(timeout);
       };
    },[]);

    return isLoading ? ( null ) : (
      <View>
        <ActivityIndicator color='#009b88' size='large' />
      </View>
    )
  }
函数加载指示器视图(){
const[isLoading,seIsLoading]=React.useState(true);
React.useffect(()=>{
常量超时=设置超时(()=>{
seisloding(假);
}, 5000);
return()=>{
clearTimeout(超时);
};
},[]);
返回isLoading?(空):(
)
}

你可以将所有你想要的东西放入而不是null

我的函数不是要确定应用程序是否正在加载,我已经确定我的函数的return语句中的所有内容都表示应用程序正在加载。我只想5秒钟后出现“请等一下…”