I'm trying to find a proper way to "clear" my first fetch request if a second one is made.
I have this:
const [data, setData] = useState([]);
const callAPI = async () => {
const api = await fetch(
`my API`
);
const data = await api.json();
setData(data);
The user can call the same api again to request similar or different date for a second, third, fourth time.... and I'm having issues with rendering information after the first call. I receive the info from the fetch request but React won't load the info properly or at all. I'm wondering if there is a proper way to do something like this:
const [data, setData] = useState([]);
const callAPI = async () => {
** clearFetch() **
const api = await fetch(
`my API`
);
const data = await api.json();
setData(data);