DEV Community

Discussion on: 🔥 Learn React in 10 Tweets (with hooks)

Collapse
nibble profile image
Joseph Mawa • Edited on

Concise explanation. Simple to grasp. Thanks a bunch for the article. One quick question though.
Why does esLint give a warning whenever i use a variable defined outside, inside the effect without passing it as a dependency. Like:

   useEffect( () => {
       fetch(url)
      .then(res => res.json())
      .then( data => console.log(data))
}, [])

url is defined outside and obviously i want to fetch the data once after initial render but esLint gives a warning requiring me to pass it as a dependency. Does it mean i can't use a variable defined outside the effect if i don't pass it as a dependency?