2.2.1 • Published 3 years ago

kedge v2.2.1

Weekly downloads
1
License
MIT
Repository
github
Last release
3 years ago

Kedge

Build Status Latest Stable Version Total Downloads License

Easy to use global state hook for React.

Kedge

Read a little bit more here.

Installation

npm install kedge

Usage

import { createStore, useStore } from 'kedge';

const priceStore = createStore();

function PriceComponent() {
  const price = useStore(priceStore);
  useEffect(fetchPrice, []);

  return (
    <div>
      Price: { price }
    </div>
  );
}

function fetchPrice() {
  priceStore.set(73);
}

API

  • const store = createStore(initialState, optionalName)

    Creates a Store with initial value. Optionally, it accepts a store name that is used in React Dev Tools

  • const state = useStore(store)

    Returns current state from the Store and subscribes the component to it. If the Store changes state the component will re-render.

  • Store.set(newState)

    Sets Store state and re-renders all components that use it.

  • Store.reset()

    Sets Store to initial value and re-renders all components that use it.

2.2.1

3 years ago

2.2.0

5 years ago

2.1.0

5 years ago

2.0.0

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago

0.9.2

5 years ago

0.9.1

5 years ago

0.9.0

6 years ago