S
S
SerjSkachkov2020-10-26 11:54:06
React
SerjSkachkov, 2020-10-26 11:54:06

What about useMemo and dependency?

There is a memoized function.

An example in which there are 3 dependencies value1, value2, value3.
But we use only 2 dependencies value1, value2 in the function.

We get
the warning react hook usememo has an unnecessary dependency "value3" what are the solutions?

const memoizedValue = useMemo(() => computeExpensiveValue(value1, value2 ), [value1, value2, value3]);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Filippov, 2020-10-26
@vicodin

In your example, nothing depends on value3, you can remove it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question