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

antd-modal

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

antd-modal

## Features

  • 0.1.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
7
increased by40%
Maintainers
1
Weekly downloads
 
Created
Source

antd-modal

Features

  • 不中断数据流

    我们经常使用的 API 唤起 方式打开弹窗,如:

import { Button, Modal } from 'antd';

Modal.confirm({
  title: 'Modal.show() 打开对话框',
  content: 'Some descriptions',
  onOk() {
    console.log('OK');
  },
  onCancel() {
    console.log('Cancel');
  },
});

但是这个功能开发者应该慎用,因为使用 API 打开对话框,实际上会断掉数据流,并不是一个好的实践。

当使用 modalRef.current.show 这种方式时相当于利用 ref 保留了自动管理的生命周期,数据流也不会中断,外部 Context 也能很好的保留。

  • 自动随父节点销毁

    同样的,全局 Modal.show 这种方式弹框由于是将组件挂载到了全局,所以很难做到自动随父组件销毁,必须手动额外调用销毁方法,使用反而变得复杂。

Usage

  • 主要用法
import React, { useRef } from 'react';
import Modal from 'antd-modal';

const App = () => {
  const modalRef = useRef<Modal>(null);
  const onClick = async () => {
    const flag = await modalRef.current!.show(props, children);
    if (flag & Modal.OK) {
      // 点击了确定按钮
    }
  };
  return (
    <>
      <Modal ref={modalRef} />
      <button onClick={onClick}>打开弹窗</button>
    </>
  );
};
  • 其他用法
const flag = await modalRef.current.confirm({...});
const flag = await modalRef.current.success({...});
const flag = await modalRef.current.warn({...});
const flag = await modalRef.current.error({...});

Props

FAQs

Package last updated on 29 Mar 2021

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