Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

open modal useState

<script src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script>
<div id="App"></div>
<script type="text/babel">
  const {useState} = React;

function App() {
  const [openModal, setOpenModal] = useState(false);

  const toggleModal = () => {
    setOpenModal(!openModal);
  }

  return (
    <div className="container">
      {!openModal ?
      <button type="button" onClick={toggleModal}>Open Modal</button>
      : <Modal handler={toggleModal} />
      }
    </div>
  )
}

function Modal({handler}) {

  return (
    <div className="modal" >
      <p>I'm a modal</p>
      <button type="button" onClick={handler}>Close Modal</button>
    </div>
  )
}

ReactDOM.render(<App />, document.getElementById('App'));
 </script>
Comment

PREVIOUS NEXT
Code Example
Javascript :: for each loop with arrowfunction 
Javascript :: search datatable vuetify 
Javascript :: set localstorage 
Javascript :: axios delete with data 
Javascript :: how to create package.json file in vs code 
Javascript :: leap year function javascript 
Javascript :: jquery wait for function to finish 
Javascript :: how to get variable in local storage in javascript 
Javascript :: javascript array.find 
Javascript :: fetch request javascript 
Javascript :: react-active link 
Javascript :: spotify web player 
Javascript :: javascript select multiple values 
Javascript :: json_insert mysql 
Javascript :: reverse text javascript 
Javascript :: add array to array js 
Javascript :: Burger menu bulma React 
Javascript :: how to check if the first letter of a string is capitalized or uppercase in js 
Javascript :: How to send form data from react to express 
Javascript :: javascript empty array 
Javascript :: how to loop trough an object java script 
Javascript :: javascript concat two arrays 
Javascript :: aes 256 nodejs 
Javascript :: How to get the background image URL of an element using jQuery 
Javascript :: how to generate a random salt in nodejs 
Javascript :: github actions ssh 
Javascript :: js remove form object by key 
Javascript :: Quick Git Setup 
Javascript :: how to convert an object to a list in js 
Javascript :: change the position of div using javascript 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =