📌  相关文章
📜  功能组件的事件监听器 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:04.659000             🧑  作者: Mango

代码示例1
import React, { useEffect } from 'react';

const Component = (props) => {  
  useEffect(() => {
    window.addEventListener('scroll', handleScroll);
  });
  useEffect(() => {
    return () => {
      window.removeEventListener('scroll', handleScroll);
    };
  }, []);

  function handleScroll() {
    let scrollTop = window.scrollY;
  }


  return ()
}