0.0.16 • Published 1 year ago

statedrive v0.0.16

Weekly downloads
21
License
ISC
Repository
github
Last release
1 year ago

Statedrive

easy shared state across the entire app

Concept

Each state is a unique atom to which you can attach event listeners and run state updates.

Installation

npm i statedrive or yarn add statedrive

API

For ui-lib

import {createState} from "statedrive";

For react

import {createState} from "statedrive";
import {buildReactStatedrive} from "statedrive/react";
const {} = buildReactStateDrive(react);

everything else is the same.

Basic Usage

  1. Create a state atom state.js
    import {createState} from "statedrive";
    export const userNameAtom = createState({initialValue: "Foo"});
  2. Use it within a react/ui-lib component some-component.js
    import {useSharedState} from "statedrive";
    import {userNameAtom} from "./state.js";
    export function ComponentA() {
      const [name, setName] = useSharedState(userNameAtom);
      return <input value={name} onChange={(e) => setName(e.target.value)} />;
    }
    export function ComponentB() {
      const [name] = useSharedState(userNamaeAtom);
      return <div>You Entered {name}</div>;
    }
  3. Use it within your app elsewhere (any place where hooks don't work) util.js
    import {get, set} from "statedrive";
    import {userNameAtom} from "./state.js";
    function updateName(newValue) {
      setUserNameAtom, newValue;
    }
    function getName() {
      return get(userNameAtom);
    }

And that's it, your entire app will be synced to this state and updated whenever needed.

0.0.14

1 year ago

0.0.16

1 year ago

0.0.13

3 years ago

0.0.12

3 years ago

0.0.10

3 years ago

0.0.11

3 years ago

0.0.9

3 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.3

4 years ago

0.0.4

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago