2.1.2 • Published 2 years ago

use-modal-hook v2.1.2

Weekly downloads
3
License
MIT
Repository
github
Last release
2 years ago

React hook for controlling modal components

Install

#With npm
npm install use-modal-hook --save 
#With yarn
yarn add use-modal-hook

Usage

Edit react use modal hook example

import React, { memo } from "react";
import { useModal, ModalProvider } from "use-modal-hook";
import Modal from "react-modal"; // It can be any modal

const MyModal = memo(
  ({ isOpen, onClose, title, description, closeBtnLabel }) => (
    <Modal isOpen={isOpen} onRequestClose={onClose}>
      <h2>{title}</h2>
      <div>{description}</div>
      <button onClick={onClose}>{closeBtnLabel}</button>
    </Modal>
  )
);

const SomePage = memo(() => {
  const [showModal, hideModal] = useModal(MyModal, {
    title: "My Test Modal",
    description: "I Like React Hooks",
    closeBtnLabel: "Close"
  });

  return (
    <>
      <h1>Test Page</h1>
      <button onClick={showModal}>Show Modal</button>
    </>
  );
});

const App = () => (
  <ModalProvider>
    <SomePage />
  </ModalProvider>
);

useModal(<ModalComponent: Function|>, <modalProps: Object>, <onClose: Function>): [showModal: Function, hideModal: Function]

ParamTypeDescription
ModalComponentFunctionIt can be any react component that you want to use for show modal
modalPropsObjectProps that you want to pass to your modal component
showModalFunctionIt is function for show your modal, you can pass any dynamic props to this function
hideModalFunctionIt is function for hide your modal, you can pass any dynamic props to this function
onCloseFunctionIt callback will be triggered after modal window closes

showModal(dynamicModalProps: Object)

ParamTypeDescription
dynamicModalPropsObjectDynamic props that you want to pass to your modal component

License

MIT © alexanderkhivrych

2.1.2

2 years ago

2.1.1

2 years ago

2.1.0

2 years ago

2.0.0

2 years ago

3.0.0

2 years ago

4.0.1

2 years ago

4.0.0

2 years ago

1.0.19

3 years ago

1.0.18

4 years ago

1.0.17

5 years ago

1.0.16

5 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago