📌  相关文章
📜  useeffect 清理功能 - Javascript 代码示例

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

代码示例6
function App() {
  const [shouldRender, setShouldRender] = useState(true);

  useEffect(() => {
    setTimeout(() => {
      setShouldRender(false);
    }, 5000);
  }, []);

  // don't render
  if( !shouldRender ) return null;
  // JSX, if the shouldRender is true
  return ;
}