@dudiharush/react-modal
TypeScript icon, indicating that this package has built-in type declarations

1.0.45 • Public • Published

react-modal

React Modal With Hooks

installation

run: npm i @dudiharush/react-modal

usage example

import { ModalProvider } from "@dudiharush/react-modal";

// step 1: use ModalProvider
render(
  <ModalProvider>
    <App />
  </ModalProvider>,
  rootElement,
)

// step 2: create modal component and call useModalActions()
import { useModalActions } from "@dudiharush/react-modal";

const MyModalContent = ({ title }: { title: string }) => {
  const { hideModal } = useModalActions()
  return (
    <div>
      <div>{title}</div>
      <button onClick={() => hideModal()}>close</button>
    </div>
  )
}

// step 3: create a custom hook that shows your modal:
import { useModal } from "@dudiharush/react-modal";

const useMyModalContent = () => {
  const { showModal } = useModal(MyModalContent)
  return showModal
}

// step 4: call your custom modal hook and use its returned "showModal" function:
const showModal = useMyModalContent()
  return (
    <button
      onClick={() => {
        showModal({title: 'modal title'})
      }}
    >
      open modal
    </button>
}
```

Package Sidebar

Install

npm i @dudiharush/react-modal

Weekly Downloads

4

Version

1.0.45

License

MIT

Unpacked Size

9.23 kB

Total Files

9

Last publish

Collaborators

  • dudiharush