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

disposable-component

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

disposable-component

A simple reactive API for mounting and unmounting components to the DOM

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
15
decreased by-37.5%
Maintainers
1
Weekly downloads
 
Created
Source

disposable-component

Disposable-component providse a simple reactive API for mounting and unmounting components to the DOM. This is useful for cross framework interop inside your single-page-app.

npm version Build Status

Setup

npm install --save rx disposable-component

Usage

A simple example would be to use disposable-component to build a react-modal:

import mountComponent from "disposable-component";
import React from "react";
import ReactDOM from "react-dom";

function showModal(El, props) {
  return mountComponent(
    function mount(onNext, onCompleted, onError) {
      el = document.createElement("div");
      document.body.appendChild(el);

      ReactDOM.render(
        <El {...props} close={onCompleted} onNext={onNext} />,
        el
      );
    },
    function unmount() {
      ReactDOM.unmountComponentAtNode(el);
      el.parentNode.removeChild(el);
    }
  );
}

const subscription = showModal(function MyModal() {
  return (
    <div>
      <h1>My Modal</h1>
      <button onClick={this.props.onCompleted}>Close</button>
      <button onClick={this.props.onNext.bind(null, 1)}>Save</button>
    </div>
  );
}).subscribe(
  data => console.log(data),
  err => console.error(err)
);

subscription.dispose(); // close the modal

FAQs

Package last updated on 30 Nov 2017

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