Great post.
On fetching data example I get "0" as output in console when I rendered the first time.
If i work with "Sandbox" and make changes on the file, then the data Objects shows in the console.
Why?
importReact,{useEffect,useState}from"react";constApp=()=>{const[data,setData]=useState("");constfetchData=async()=>{constapi=awaitfetch("https://jsonplaceholder.typicode.com/todos/");setData(awaitapi.json());};console.log(data);useEffect(()=>{fetchData();},[data]);return<><h1>I am fethcing some fake data's</h1></>;};exportdefaultApp;
This one also woks fine just put the state as your effect dependencies. So it will fetch the data when the value of our state variable changes.
I have a repo on useEffect fetch api, your can visit that -> github.com/Ratul-oss/github-users-...
Great post.
On fetching data example I get "0" as output in console when I rendered the first time.
If i work with "Sandbox" and make changes on the file, then the data Objects shows in the console.
Why?
run this code in stackblitz.com sandbox has some bugs in this case
Hello Ratul
Thank you for the reply.
I Think it does not work well, because it fetch the Data endless...
But i took the time and researched for a solution and here is it:
thanks to your post I was able to be successful!
Nice solution
This one also woks fine just put the state as your effect dependencies. So it will fetch the data when the value of our state variable changes.
I have a repo on useEffect fetch api, your can visit that -> github.com/Ratul-oss/github-users-...
:)
So when you run this code it never stops.