2.0.3 • Published 5 years ago

usemodal-portal v2.0.3

Weekly downloads
219
License
MIT
Repository
-
Last release
5 years ago

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

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.0.1

6 years ago