react icon indicating copy to clipboard operation
react copied to clipboard

Why imperative code using refs should be avoided?

Open dante01yoon opened this issue 3 years ago • 0 comments

Hi, in few weeks, I found useImperativeHandle is quiet handy for

  • encapsulation how child component state changing logic implemented, no event handler needs to pass down to child component when using this hook.
  • ref can be defined using typescript interface in child component , which that's all parent component should know.
  • in the same manner of first one, parent component doesn't filled with complex logic functions, which gives parent component more readability nonetheless it can still use tens of child components.

but document says using useImperativeHandle should be avoided in most cases? I can't find reason

dante01yoon avatar Jul 31 '22 10:07 dante01yoon