DEV Community

geniGit2921
geniGit2921

Posted on

REactjs Axios loop of death

can someone explain me why this does loop forever when I place it in the app's (functional component)


const [data, setData] = useState()

const fetchData = async() => {
const queryResults = await axios.post(
Constants.GRAPHQL_API, {
query: Constants.GET_TEST
}
);
const result = queryResults.data.data
setData(result)
};
fetchData();

console.log(data);

Top comments (2)

Collapse
 
genigit2921 profile image
geniGit2921

I think I got it working, I place this in a separate function component, and called it from app.js

Collapse
 
genigit2921 profile image
geniGit2921

I did place it in a use effect then I can kill the loop, but I want to be able to call it on login