📌  相关文章
📜  隐藏组件模糊反应挂钩 - Javascript 代码示例

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

代码示例1
const React,{ useState, useMemo } = React

const usToggleOnFocus = (initialState = false) => {
  const [show, toggle] = useState(initialState);
  
  const eventHandlers = useMemo(() => ({
    onFocus: () => toggle(true),
    onBlur: () => toggle(false),
  }), []);

  return [show, eventHandlers];
}

const Demo = () => {
  const [show, eventHandlers] = usToggleOnFocus();

  return (
    
{show &&
Content
}
); }; ReactDOM.render( , demo );