Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

custom portal react

import { useEffect, useRef, useState } from 'react'
import { createPortal } from 'react-dom'

export function Portal({ children, selector }) {
  const ref = useRef()
  const [mounted, setMounted] = useState(false)

  useEffect(() => {
    ref.current = document.querySelector(selector)
    setMounted(true)
  }, [selector])

  return mounted ? createPortal(children, ref.current) : null
}

// Usage
<Portal selector="#modal">
  <h1> Hey </h1>
</Portal>
Comment

PREVIOUS NEXT
Code Example
Typescript :: Electron WebContents context-menu 
Typescript :: get number of digits in an integer python without converting to string 
Typescript :: makestyles material ui typescript 
Typescript :: tsconfig-paths/register mocha 
Typescript :: typescript class inheritance 
Typescript :: how to list elements of an array C# 
Typescript :: typeorm transaction example 
Typescript :: adding font in nextjs 
Typescript :: removing directories in linux 
Typescript :: typescript omit 
Typescript :: import luno pricing to google sheets api 
Typescript :: typescript doesnt read .d.ts 
Typescript :: apexcharts marker onclick 
Typescript :: Custom _App with getInitialProps typescript example 
Typescript :: sort even dont exists meta wordpress 
Typescript :: import dropdown module p-dropdown 
Typescript :: Route.component does not have any construct or call signatures - React Router with TypeScript 
Typescript :: different keymaps in the following locations 
Typescript :: can we do system testing at any stage 
Typescript :: Angular 12: Trigger multiple child components at once 
Typescript :: rtk configurestore 
Typescript :: ionic 3 angular replacements or alternatives 
Typescript :: how to send attachments to api 
Typescript :: HOC Generic using React Typescript 
Typescript :: header elements on right 
Typescript :: nest js guard canactive 
Typescript :: webintent plugin cordova 
Typescript :: download objects under a prefix in golang 
Typescript :: components swift separator vo sequenc of characters 
Typescript :: python Implement the function is_even(number) which gets an integer as input parameter and checks, if this input is even or not 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =