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 :: convert string to a number javascript 
Javascript :: Difference Between for...of and for...in Statement 
Javascript :: javascript how to select a array 
Javascript :: js max number in array mdn 
Javascript :: null is true or false javascript 
Javascript :: node.js folder structure 
Javascript :: react spring transition animations 
Javascript :: context menus use 
Javascript :: javascript print square 
Javascript :: data table buttons 
Javascript :: create file node 
Javascript :: javascript save multiple images to server 
Javascript :: js toggle div 
Javascript :: TypeError: error.status is not a function 
Javascript :: javascript shell 
Javascript :: js upload file size limit 
Javascript :: javascript error null 
Javascript :: js date toisostring with timezone 
Javascript :: jquery show hide animation slide 
Javascript :: how to remove the elements from array and how to replace a new element in javascript 
Javascript :: find element vs find elements 
Javascript :: javascript side effects 
Javascript :: Looping arrays with for loop 
Javascript :: tradingview custom data feed 
Javascript :: mock anonymous function jest 
Javascript :: money formatting javascript 
Python :: no module named social_django 
Python :: python pip install matplotlib 
Python :: drop a range of rows pandas 
Python :: where to import messages in django 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =