/* 
- Portals provide a first-class way to render children into a DOM node that 
exists outside the DOM hierarchy of the parent component. 

- Creates a Portal and renders content in the provided container(DOM Node) outside 
the default hierarchy.

- It’s important to note that the createPortal() function will not create the 
containerElement for us, we have to explicit do that in our "index.html" file 
E.g <div id="react-modal"></div>

- Creating a Portal accepts two parameter 
    content: any valid renderable React element
    containerElement: a valid DOM element to which we can append the content
	E.g ReactDOM.createPortal(content, containerElement);
*/

  import { createPortal } from 'react-dom';

  function Modal() {
    return createPortal(<section>
                        <p>This is an example or React Portal</p>
                        </section>, 
                        document.getElementById("react-modal"));
  }
  export default Modal;

// With love @kouqhar// 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>//  REACT
// createPortal lets you render some children into a different part of the DOM.
// the most notable/common entry point of react and JSX is <div id="root><div>
// with createPortal you can add a different dom Node to the index.html, target/select it and 
// add inject a JSX/Html content to it.  
// 
import { createPortal } from 'react-dom';

function MyComponent() {
  return (
    <div style={{ border: '2px solid black' }}>
      <p>This child is placed in the parent div.</p>
      {createPortal(
        <p>This child is placed in the document body.</p>,
        document.body
      )}
    </div>
  );
}

Javascript相关代码片段

ajax to controller not mapping list of ints

pdf.js shortcode

js length of string

ng build prod not working

or truth table

js or symbol

Git - Ignore node_modules folder everywhere

.net and javascript date functions format

js element in viewport

object detection in react native

remove repeated elements in array javascript

useTransission react

custom cursor for react

react get blue outline on routing Links

get rid of blue button effect on react links

nextjs remote url image

react router v6 basic code

lua table to json online

download video from url javascript

jquery set max length input

JS not selecting the element

react native clock

shadcn toast not showing

express folder structure

audio element

javascript set display of elem to block

react phone number input

tailwind intellisense not working with react

cannot find name 'cy'

submit form react

footer react bootstrap

angular interview questions and answers

trigger alert if button is clicked

change query params

verify control code iban javascript

react-spring

Next JS solve the Hydration error

how can i set a new expo project

generate aes key

storage capacity on browser

nix flake Javascript projects

reset udemy course progress

zod Input file schema with shadcn

wordpress rest api print json pretty

extract string csv js

remove extra space string javascript

count letters in string javascript

exract string js

lazygit nvim

ex:javascript loop

js slice last element

Multiply a number with .17 and round up to .25

sweetalert 2

booking calendar js

process.env is kept

AnimationEvent has no function name specified!

jquery date picker wordpress enque

js check in view

settimeout event in input in javascript in react

node option size

docker react app

React Modal using Dialog

how to create dynamic object in javascript

how to create global variable in postman

javascript interview questions tricky

how to create workflow request in postman

mysql json_extract array

parse response body in postman

query param generator js

jest function async API

React portal

i18next suppoeort react

puppeteer page evaluate

react router dom use navigate

react create array from another array

how to delete global variable in scripts postman

Where does closure variables stored in javascript

Where does local variables stored in javascript

nodejs là gì

addEventListener for multiple selector