React Flashcards

1
Q

Why might a react app run slow?

A

Causes for latency in a react app:

  1. state being held too high, because this causes all children components to re-render whenever state changes
  2. expensive functions, need to implement useMemo
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

what is the useMemo hook used for?

A

useMemo is a React hook that memorizes the output of a function. useMemo accepts two arguments: a function and a list of dependencies. useMemo will call the function and return its return value. Then, every time you call useMemo again, it will first check if any dependencies have changed. If not, it will return the cached return value, not calling the function. If they have changed, useMemo will call the provided function again and repeat the process.
This should remind you of the useEffect hook: both useMemo and useEffect accept lists of dependencies. The only difference is that useEffect is intended for side-effects (hence the name), while functions in useMemo are supposed to be pure and with no side-effects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly