Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
我们经常使用的 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
这种方式弹框由于是将组件挂载到了全局,所以很难做到自动随父组件销毁,必须手动额外调用销毁方法,使用反而变得复杂。
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({...});
FAQs
## Features
The npm package antd-modal receives a total of 7 weekly downloads. As such, antd-modal popularity was classified as not popular.
We found that antd-modal demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.