New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react-syncing

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-syncing

Sync state in React

latest
npmnpm
Version
1.0.23
Version published
Weekly downloads
2
-92.31%
Maintainers
1
Weekly downloads
 
Created
Source

react-syncing

Synchronize state between react components using pubsub.

Instructions

Extends your main class (the typical App) from Master, the rest from Slave, the source of trust will be the Master

If you extends from Master or Slave:

instead of using setState, use set,

instead of using componentWillUnmount, use willUnmount,

and instead of using componentDidMount, use didMount

That's all!

Usage

import {Master} from "react-syncing";

export class App extends Master {
  render() {
    return (
      <div>
        <p>{this.state.name}</p>
        <NameInput />
      </div>
    );
  }
}

From another component

import {Slave} from "react-syncing";

export class NameInput extends Slave {
  didMount() {
    // Default name
    this.set({ name: "Name" });
  }
  render() {
    return <input onInput={e => this.set({ name: e.target.value })} />;
  }
}

Performance

https://kidandcat.github.io/sync-performance/

All the squares are syncing the state with the Root element that keeps changing the color and adding new elements. Only the firs Square receives the color as a prop. The first square shows the number of rendered elements.

In my computer, it renders 200 elements without any issue. After that, it start suffering delays, I would need to test react alone too. Anyway, obviously, you shouldn't be syncing every single component of your webpage.

License

MIT

FAQs

Package last updated on 15 Sep 2018

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