Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

hide component blur react hooks

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 (
    <div>
      <input {...eventHandlers} />
      {show && <div>Content</div>}
    </div>
  );
};

ReactDOM.render(
  <Demo />,
  demo
);
Comment

PREVIOUS NEXT
Code Example
Javascript :: js get word before question mark 
Javascript :: javascript event get div text 
Javascript :: js % 
Javascript :: react native expo PayloadTooLargeError: request entity too large 
Javascript :: change span value according to textfierld value in jquery 
Javascript :: react js error stackoverflaw 
Javascript :: agora token Renewal 
Javascript :: call apply mnemonic javascript 
Javascript :: GRAPHQL_VALIDATION_FAILED) GraphQLError: Enum ENUM_MESSAGE_TYPE" cannot represent non-enum value: comment. Did you mean the enum value comment 
Javascript :: turn any function into promise 
Javascript :: pragmatic view on the meaning of life 
Javascript :: react native controlling device brightness 
Javascript :: javascript intl.datetimeformat brasil 
Javascript :: switch is not exported from react-router-dom 
Javascript :: convert componentDidUpdate into useEffect 
Javascript :: You may need an appropriate loader to handle this file type when importing images 
Javascript :: web3 js connect to ropsten 
Javascript :: open json file in JS in order to access data 
Javascript :: document.body.insertBefore 
Javascript :: how to check length checkbox has been checked 
Javascript :: Angular : pass data to component loaded via route 
Javascript :: appendchild js 
Javascript :: Import UI library modularized in nuxtjs 
Javascript :: focus on image when click 
Javascript :: how to ask a question in a popup javascript 
Javascript :: cookie clicker get all badges hack 
Javascript :: build class component react 
Javascript :: karma get attribute 
Javascript :: PASSWORD REDIRECT 
Javascript :: Arrow Function Shorthand javascript 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =