Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-modal-store

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-modal-store

global manage react modal

  • 1.0.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
3
increased by200%
Maintainers
1
Weekly downloads
 
Created
Source

react-model-store

Centralized management of modal. Manage visible prop and handle onClose event Automatically

React 弹窗管理的思考

npm MIT

Install

$ npm install react-model-store --save

Usage

import React, { useContext } from 'react';
import ReactDOM from 'react-dom';
import { Modal } from 'antd';
import { ModalStore, useModal } from 'react-model-store';

function Modal1({ text, visible, onCancel, afterClose }) {
  return (
    <Modal title="It's m1" visible={visible} onCancel={onCancel} afterClose={afterClose}>
      <div>{text}</div>
    </Modal>
  );
}

function Modal2({ name, visible, onCancel, afterClose }) {
  return (
    <Modal title="It's m2" visible={visible} onCancel={onCancel} afterClose={afterClose}>
      <div>{name}</div>
    </Modal>
  );
}

const modalMap = {
  m1: Modal1,
  m2: Modal2,
};

function App() {
  return (
    <ModalStore modalMap={modalMap} destroyOnClose="afterClose">
      <Content />
    </ModalStore>
  );
}

function Content() {
  const dispatchModal = useModal();

  return (
    <div>
      <button type="button" onClick={() => dispatchModal('m1', { text: 'm1 content' })}>
        show m1
      </button>
      <button type="button" onClick={() => dispatchModal('m2', { name: 'm2 content' })}>
        show m2
      </button>
    </div>
  );
}

ModalStore

PropDescriptionTypeDefault
visiblePropNamethe prop name that controls the modal displaystring'visible'
onClosePropNamethe prop name that closes the modal by set visible = falsestring'onCancel'
destroyOnCloseWhether to unmount modal on close, if this value is a string, it'll unmount when calling this method instead of onClosePropName`booleanstring`
modalMapall the modals by key-valueobject

useModal

The hook return a function to open a new modal.

const dispatchModal = useModal();

<button onClick={() => dispatchModal('key', {})}></button>;

License

MIT

Copyright (c) 2020-present xiemengxiong

FAQs

Package last updated on 16 Nov 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc