Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
react-disposable-modal
Advanced tools
React-disposable-modal is a reactive API for building modal components in React.
React-disposable-modal is a reactive API for building modal components in React.
You want to build a modal in React, but don't want that modal to be
inserted in the DOM immediately where the Modal is rendered, instead you
want it to be appended to document.body
.
Modals have are inherently an asyncronous ui component. A modal is displayed, at some point in the future an action is taken from within the modal, and then it is closed. React-disposable-modal provides a reactive API for handling that asyncronous behavior.
yarn add react-disposable-modal
There are two ways to use react-dispoable-modal: an imperative and declarative API:
createCancelableModal(ModalComponent, props)
- Takes two parameters, a
custom modal component and optional parameters to pass to the modal.
ModalComponent
will be rendered with three extra props:
onNext
- Use to pass data to the subscription that invoked the modal. Can be called multiple times.
onError
- Use to pass an error to the subscription that invoked the modal.
onCompleted
- Use to close the modal.
import { createCancelableModal } from "react-disposable-modal";
import React from "react";
class Modal extends React.Component {
render() {
return (
<div>
<div className="screen" />
<div className="modal">
<h1>My modal for {this.props.name}</h1>
<button onClick={this.props.onCompleted}>Cancel</button>
<button
onClick={() => (
this.props.onNext("I did it!"), this.props.onCompleted()
)}
>
Save
</button>
</div>
</div>
);
}
}
class App extends React.Component {
render() {
return (
<div>
<button onClick={this.showModal}>Show Modal</button>
</div>
);
}
showModal() {
const subscription = createCancelableModal(Modal, {
name: "you",
}).subscribe(data => {
data === "I did it!";
});
subscription.dispose(); // force the modal closed
}
}
Anything put inside the Modal
component will be appended to document.body
.
import { Modal } from "react-disposable-modal";
import React from "react";
class App extends React.Component {
state = { showModal: false };
render() {
return (
<div>
<button onClick={() => this.setState({ showModal: true })}>
Show Modal
</button>
{this.showModal && (
<Modal>
<div>
<div className="screen" />
<div className="modal">
<h1>My modal for you</h1>
<button onClick={() => this.setState({ showModal: false })}>
Cancel
</button>
<button onClick={() => this.setState({ showModal: false })}>
Save
</button>
</div>
</div>
</Modal>
)}
</div>
);
}
}
FAQs
React-disposable-modal is a reactive API for building modal components in React.
The npm package react-disposable-modal receives a total of 10 weekly downloads. As such, react-disposable-modal popularity was classified as not popular.
We found that react-disposable-modal demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 13 open source maintainers 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.