0

I am working on a project, where I am using conditional rendering. I am not sure what the cause but I am not getting data from api after refreshing the page.

This is obviously not the desired behavior, what am I missing here? This is my fetch request code:

useEffect(() => {
  axios
    .get(path)
    .then((res) => {
      setRoundData(res.data[1]);
      setStudentData(res.data[2]);
      setFilterData(res.data[2]);
    })
    .catch((err) => console.log(err));
}, [path]);
1
  • Without seeing the code it will be very difficult to help. I suggest you edit the question and include at least your fetch logic. Commented Jun 2, 2023 at 10:16

1 Answer 1

1

Create a async function which runs each time the path changes. You could try something like this:

useEffect(() => {
  async function fetchData() {
    const res = await axios.get(path);
    setRoundData(res.data[1]);
    setStudentData(res.data[2]);
    setFilterData(res.data[2]);
  }
  
  fetchData();
}, [path]);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.