DEV Community

Discussion on: The React useMemo Hook Made Simple

Collapse
 
lexlohr profile image
Alex Lohr

Basically, what useMemo does is creates a state and updates it with an effect:

const result = useMemo(() => fibonacci(number), [number])
Enter fullscreen mode Exit fullscreen mode

almost equals

const [result, setResult] = useState()
useEffect(() => { setResult(fibonacci(number)) }, [number])
Enter fullscreen mode Exit fullscreen mode

except that the first setResult dispatcher call is handled synchonously.