Make focus and blur input with react hooks
问题 I want to show input results when I focused on this input and hide this result when I blur. I 'v used this code but not work with blur useEffect(() => { if (inputElMovie.current.focus) { console.log("meme") } }, [movies,inputElMovie]); 回答1: You don't need useEffect for this case. Create a custom hook with useState() , and return a boolean ( show ), and an object of event handlers you can spread on the input: const { useState, useMemo } = React const usToggleOnFocus = (initialState = false) =>