New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

usemodal-portal

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

usemodal-portal

A React hook to handle with modals, using portal!

latest
npmnpm
Version
2.0.3
Version published
Maintainers
1
Created
Source

usemodal-portal

A React hook to handle with modals, using portal!

codesandbox example

installation

npm install usemodal-portal

//or

yarn add usemodal-portal

How to use

useModal accepts a function that has the method to close the modal as a parameter and returns a React component.

import { useModal } from 'usemodal-portal'

function YourPage() {
  const {Modal, toggleRenderModal} = useModal(
    (toggleRenderModal) => <YourModalComponentHere 
      onClose={toggleRenderModal} 
    />
  )

  return (
    <>
      <button onClick={toggleRenderModal}>open modal</button>
      <Modal />
    </>
  )
}

By default when modal opens, it will add some styles to your body element to avoid scroll. To disable it, just add a second param to useModal hook:

import { useModal } from 'usemodal-portal'

function YourPage() {
  const {Modal, toggleRenderModal} = useModal(
    (toggleRenderModal) => <YourModalComponentHere 
      onClose={toggleRenderModal} 
    />,
    { disableBodyControl: true }
  )

  return (
    <>
      <button onClick={toggleRenderModal}>open modal</button>
      <Modal />
    </>
  )
}

useModal has typescript support by default and was made using TSDX

Keywords

react

FAQs

Package last updated on 30 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts