简体   繁体   English

在反应js中刷新页面时加载问题

[英]Loading Issue while refreshing the page in react js

I create the header nav bar.我创建了标题导航栏。 the data of the navbar is getting dynamically.导航栏的数据是动态的。

const [navItem, setNavItem] = useState([]);
  useEffect(() => {
    fetch("https://localhost//wp-json/wp/v2/pages")
      .then((res) => res.json())
      .then((data) => {
        data.sort((a, b) => a.id - b.id);
        setNavItem(data);
      });
  }, []);

But the problem is when I refresh the page it take sometime to load the data.但问题是当我刷新页面时需要一些时间来加载数据。 But I don't want this how can I solve this issue?但我不想要这个我该如何解决这个问题? 在此处输入图像描述

在此处输入图像描述

You can try to use the useQuery hook.您可以尝试使用 useQuery 挂钩。 It will consistently fetch the source for the data.它将始终如一地获取数据源。 Normally, you should not have any lags or delay: useQuery通常,您不应该有任何滞后或延迟: useQuery

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM