Skip to main content

One post tagged with "react"

View All Tags

Difference between useState and useMemo

· One min read
Filip Tammergård
Software Engineer at Einride

The title of this post might seem ridiculous. Of course useState and useMemo are different.

But in one sense, they are quite similar.

Consider this example:

const [state] = useState(() => {
return calculateSomething(input)
})

const memo = useMemo(() => {
return calculateSomething(input)
}, [input])