2

I use react hook useEffect like the following code for fetching data and changing state in it. For avoiding the infinite loop I add an empty array as the second parameter of the useEffect and I get this warning. Do I just ignore it or I have to fix it? If so, how can fix it? I just want the componentDidMount effect here. I appreciate any idea?

useEffect(() => {
 fetch('/login')
 .then(response => {
   if (response.ok) fetchAll() 
   else setLoading({ ...loading, signin: true, progress:false });     
 }).catch(() =>{
   setLoading({ ...loading, signin: true, progress:false });
 })
},[]);
F-Fardin
  • 418
  • 1
  • 7
  • 21

1 Answers1

0

try this, this should fix the warning

useEffect(() => {
 fetch('/login')
 .then(response => {
   if (response.ok) fetchAll() 
   else setLoading(loading => ({ ...loading, signin: true, progress:false }));     
 }).catch(() =>{
   setLoading(loading => ({ ...loading, signin: true, progress:false }));
 })
},[]);