I don't understand what this code does
useEffect(() => {
document.addEventListener('input', event => {
if (event.target.tagName.toLowerCase() !== 'textarea') {
return
}
autoExpand(event.target)
}, false)
}, [])
Let me try to explain what you have in your code.
About
useEffecthook you can read in the documentation:In your case the dependency array is empty
[]which means it is called only once when the functional component loaded. Similarly like in class based component but a combined life-cycle events, from the docs:If you have an object in the dependency array, it will trigger again the passed function once it is changing.
I suggest to read further about
useEffecthook in more details below:https://reactjs.org/docs/hooks-effect.html
It will help you to understand deeper. I hope that helps!