我不知道下面是做什么的

I dont know what the following does

我不明白这段代码的作用

useEffect(() => {    
    document.addEventListener('input', event => {
      if (event.target.tagName.toLowerCase() !== 'textarea') {
        return
      }
      autoExpand(event.target)
    }, false)
  }, [])

让我试着解释一下您的代码中包含的内容。

关于 useEffect 钩子你可以在文档中阅读:

The Effect Hook lets you perform side effects in function components.

在你的例子中,依赖数组是空的[],这意味着它只在功能组件加载时被调用一次。与基于 class 的组件类似,但合并了生命周期事件,来自文档:

If you’re familiar with React class lifecycle methods, you can think of useEffect Hook as componentDidMount, componentDidUpdate, and componentWillUnmount combined.

如果依赖数组中有一个对象,一旦它发生变化,它会再次触发传递的函数。

我建议进一步阅读以下有关 useEffect 挂钩的更多详细信息:
https://reactjs.org/docs/hooks-effect.html

它将帮助您更深入地了解。希望对您有所帮助!