react
react copied to clipboard
Why imperative code using refs should be avoided?
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