scrimba
Frontend Career Path
React basics
Meme generator
useEffect dependencies array
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

useEffect dependencies array
AboutCommentsNotes
useEffect dependencies array
Expand for more info
App.js
run
preview
console
import React from "react"

export default function App() {
const [starWarsData, setStarWarsData] = React.useState({})
const [count, setCount] = React.useState(0)

console.log("Component rendered")

// side effects
React.useEffect(function() {
console.log("Effect ran")
// fetch("https://swapi.dev/api/people/1")
// .then(res => res.json())
// .then(data => console.log(data))
})

return (
<div>
<pre>{JSON.stringify(starWarsData, null, 2)}</pre>
<h2>The count is {count}</h2>
<button onClick={() => setCount(prevCount => prevCount + 1)}>Add</button>
</div>
)
}


Console
"Component rendered"
,
"Effect ran"
,
/index.html
-8:01