|
|
|
|
|
by wokwokwok
2017 days ago
|
|
> However, if you only reference inputRef inside useEffect then it'll always reference the DOM node so you don't need to worry about it being undefined. This isn't correct; it's well documented [1], but people seem to often think this is true; if you reference it in multiple places or not is irrelevant. Passing a ref in to the dependencies of `useEffect` doesn't work either. Mostly I like hooks, but this one in particular seems to trip people up a lot; I'd go as far as to say that using callback refs should be the only supported way of using them; the normal one is pretty much broken by default for any component that isn't entirely trivial. [1] - I think https://medium.com/@teh_builder/ref-objects-inside-useeffect... covers this pretty carefully. |
|