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

react-shared-workspace

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-shared-workspace

Share state across siblings!

latest
npmnpm
Version
0.2.0-1
Version published
Maintainers
1
Created
Source

react-shared-workspace

Share state across siblings!

Install

yarn add react react-shared-workspace

Usage

import React from "react";
import ReactDOM from "react-dom";
import { Workspaces, createWorkspace } from "react-shared-workspace";

// provide initial state to workspace
const Workspace = createWorkspace({
  count: 0
});

function Counter() {
  return <Workspace>{({ state }) => <span>{state.count}</span>}</Workspace>;
}

function IncrementButton() {
  return (
    <Workspace>
      {({ setState }) => (
        <button
          onClick={() => {
            setState(state => ({
              count: state.count + 1
            }));
          }}
        >
          Up
        </button>
      )}
    </Workspace>
  );
}

function DecrementButton() {
  return (
    <Workspace>
      {({ setState }) => (
        <button
          onClick={() => {
            setState(state => ({
              count: state.count - 1
            }));
          }}
        >
          Down
        </button>
      )}
    </Workspace>
  );
}

function App() {
  return (
    <Workspaces>
      <Counter />
      <IncrementButton />
      <DecrementButton />
    </Workspaces>
  );
}

ReactDOM.render(<App />, document.getElementById("root"));

How it works?

The Workspaces component stores all the state so put it high up in the react tree. createWorkspace returns a Workspace component whose state is linked across all of it's instances. When all instances of Workspace unmount, the state for that workspace is cleaned up.

FAQs

Package last updated on 20 Apr 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