Getting call from Axios

here is my code.

  useEffect(() => {
    axios.get("https://jsonplaceholder.typicode.com/posts/1").then((response) => {
      const globalFilterData = (response.data)
      setPost(globalFilterData);
      console.log(post)
    });
  }, []);

and my API look like this
['peeyush' , 'gupta' , 'frontend' , 'React']

how to fetch data from there.

You are going to have to give us something more to go on here.

You can’t log post right after the useState setter (it will be undefined or whatever you initialized the state as). Create a useEffect for logging state variables.

useEffect(() => {
  console.log(post)
}, [post]) 

Don’t know what you mean by that?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.