Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

React closing a dropdown when click outside

const Home = forwardRef(({ open, setOpen }, ref) => {
  console.log(open);

  return (
    <section ref={ref}>
      <h1>Feels good to be home!</h1>

      <button className="secondary" onClick={() => setOpen(!open)}>
        Dropdown Toggle
      </button>

      {open && (
        <ul>
          <li>One</li>
          <li>Two</li>
        </ul>
      )}
    </section>
  );
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript loading animation on button click 
Javascript :: how to find out what a string ends with in javascript 
Javascript :: Getting One Value from an Array of Items 
Javascript :: find in js 
Javascript :: knex insert multiple rows 
Javascript :: what is js 
Javascript :: event handler 
Javascript :: react native intro slider 
Javascript :: send data from form to another page angular 
Javascript :: is javascript a front end or backend language 
Javascript :: check property exists 
Javascript :: nodejs ecommerce cms 
Javascript :: file-saver npm 
Javascript :: exports in node js 
Javascript :: syntax of the ternary operator 
Javascript :: js concate map 
Javascript :: how to set three js canvas width 100% 
Javascript :: Angular JS Interpolation 
Javascript :: main js pass data to vue 
Javascript :: react native image border radius not working 
Javascript :: plus sign javascript 
Javascript :: search in array javascript 
Javascript :: how to declare variables javascript 
Javascript :: redux reducer example 
Javascript :: dom in javascript 
Javascript :: prototype example 
Javascript :: npm ERR! missing script: build:dev 
Javascript :: js array delete specific element 
Javascript :: pure component in react 
Javascript :: how to prevent previous radio button active react native 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =