2.0.3 • Published 4 years ago

usemodal-portal v2.0.3

Weekly downloads
219
License
MIT
Repository
-
Last release
4 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

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.0.1

4 years ago