0

I have a large code base in React class components and some are so complex, that I do not want to refactor them to React functional components. For one function, I need memoization, so my question is:

Is there an equivalent for React functional component's useCallback in React classic components?

user3601578
  • 1,310
  • 1
  • 18
  • 29

1 Answers1

0

I think you'd have to use something like static getDerivedStateFromProps() to listen on the changes in the variable, and maybe use shouldComponentUpdate() as a workaround/manual memoization. In getDerivedStateFromProps() you would call your function in case of changes in the variables you want, and In shouldComponentUpdate() you should return false if your logic doesn't match.

Yasser hennawi
  • 735
  • 4
  • 10