简体   繁体   中英

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. It will consistently fetch the source for the data. Normally, you should not have any lags or delay: useQuery

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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