📅  最后修改于: 2022-03-11 15:03:13.603000             🧑  作者: Mango
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
);