D
D
dc65k2020-04-16 14:37:48
React
dc65k, 2020-04-16 14:37:48

How to optimize rerender in React?

Hello. Guys, tell me how to optimize so that the re-render would be only if the cDOptions prop has changed?
https://codepen.io/dc65k/pen/xxwbKOm
I tried these ways, but it didn't work:

const memoizedCallback = useCallback(
  () => {
    setCDOptions(setOptions())
  },
  [cDOptions]
)
return memoizedCallback

const memoizedValue = useMemo(() => setCDOptions(setOptions()), [cDOptions])
return memoizedValue

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question