Apologies. React noob here.
Got an issue where my code has stuck on a never ending loop. I've stripped the code down only to the part I believe that's causing the problem.
function Packages(){
const [packages, setPackages] = useState([]);
useEffect(() => {
if(!packages){
getPackages();
}
});
const getPackages = async () => {
const resp1 = await instance.get('https://jsonplaceholder.typicode.com/todos/1');
setPackages(resp1);
};
}
I've used the useEffect method to match the componentDidMount. Is that correct?
The moment I comment "setPackages(resp1);" the never ending loop stops. I probably am using the useEffect and useState hooks wrong.
Appreciate any guidance on this.