scrimba
Frontend Career Path
React basics
Meme generator
useEffect cleanup function
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

AboutCommentsNotes
useEffect cleanup function
Expand for more info
WindowTracker.js
run
preview
console
import React from "react"

export default function WindowTracker() {

const [windowWidth, setWindowWidth] = React.useState(window.innerWidth)

React.useEffect(() => {
window.addEventListener("resize", function() {
setWindowWidth(window.innerWidth)
})
}, [])

return (
<h1>Window width: {windowWidth}</h1>
)
}
Console
/index.html
-5:53