0

With this code everything works properly, my data is displayed in a li list, but when I refresh the page, it does not show on my browser anymore. Can anyone tell me why? And how I should fix it?

Thank you, below is my code with React.

const HomeFeed = () => {
        const [posts, setPosts] = useState();
        const [albums, setAlbums] = useState();
        const [photos, setPhotos] = useState();
        const [homeStatus, setHomeStatus] = useState("loading");
        
        useEffect(() => {
        const allApiFetch = () => {
        const FetchPosts = fetch("https://jsonplaceholder.typicode.com/posts");
        const FetchAlbums = fetch("https://jsonplaceholder.typicode.com/albums");
        const FetchPhotos = fetch("https://jsonplaceholder.typicode.com/photos");
    
        Promise.all([FetchPosts, FetchAlbums, FetchPhotos])
          .then((values) => {
            return Promise.all(values.map((r) => r.json()));
          })
          .then(([Posts, Albums, Photos]) => {
            setPosts(Posts);
            setAlbums(Albums);
            setPhotos(Photos);
          })
          .catch((e) => {
            console.log("Caught! Err...", e);
          });
      };
      }, []);
     return (
        <>
          <Header />
          <div>
                  <ul>
                {
                    posts.map(post => <li key={post.id}>{post.title}</li>)
                }
            </ul>
                
          </div>
        </>
      );
    };
  • Every time the component is loaded it will call the useEffect which makes the Api call. If you want to load from some sort of cache you need to use localStorage or cookies. Without those, you will need to make an api call for every page load. – Rawley Fowler Jan 12 '22 at 19:39

0 Answers0