Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including use-simple-shared-state with all npm packages installed. Try it out:

require("react/package.json"); // react is a peer dependency. var useSimpleSharedState = require("use-simple-shared-state")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

use-simple-shared-state v0.0.2

SimpleSharedState React Hook

Redux is verbose. SimpleSharedState is brief.

Get It

npm install use-simple-shared-state

Basic Use

Assuming you already have a store made with simple-shared-state:

import React from "react";
import useSharedState from "use-simple-shared-state";
import store from "./store.js";

const selectors = [
    (state) => state.counter1,
    (state) => state.examples.user,
    // put as many selectors here as you need
];

export const MyComponent = () => {
    const [count1, someObject] = useSharedState(store, selectors);
    return (
        <div>
            <h1>Hello World</h1>
            <span>{count1}</span>
            <pre>{JSON.stringify(someObject)}</pre>
        </div>
    )
};

That's all there is to it.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free