Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

create react portal

// modal file s an example

import React from 'react';
import ReactDOM from 'react-dom';

// create modal and use a portal to mount it in a specific DOM point
const Modal = (props) => {
  return (
    <React.Fragment>
      {ReactDOM.createPortal(
        <div>This is the modal</div>,
        document.getElementById('modal-root'),
      )}
    </React.Fragment>
  )
}


export default Modal;

// public html doc to define where the is the portal's destination
// in this case "modal-root"

<body>
  <div id="root"></div>
  <div id="modal-root"></div>
</body>
Comment

react portal example

React Protal
Comment

PREVIOUS NEXT
Code Example
Javascript :: currency convertor api in javascript 
Javascript :: javascript reverse loop 
Javascript :: multiple line string in jquery 
Javascript :: javascript format date object to yyyy-mm-dd 
Javascript :: javascript title string 
Javascript :: how to change style of an element using javascript 
Javascript :: object length javascript 
Javascript :: prepend to array javascript 
Javascript :: slickcdn 
Javascript :: find object in array javascript with property 
Javascript :: viewchild for ngfor 
Javascript :: Rename files in a directory with node.js 
Javascript :: import react icons 
Javascript :: how to convert entered number into currency in words in javascript 
Javascript :: jquery $(document.on click 
Javascript :: javascript base 10 to base 2 
Javascript :: access variable outside for loop javascript 
Javascript :: javascript calculate 24 hours ago 
Javascript :: momentjs range 
Javascript :: javascript string methods 
Javascript :: javaScript getMilliseconds() Method 
Javascript :: regex for exactly n digits 
Javascript :: Write the JavaScript code to set the width of element to 50%; 
Javascript :: remove symbols from cpf js 
Javascript :: disable javascript firefox 
Javascript :: javascript for...in with Arrays 
Javascript :: react yup password with number string and uppercase 
Javascript :: json typicode 
Javascript :: javascript iterate through a map 
Javascript :: js get random from array 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =