1.1.1 • Published 2 years ago

@cinimod/use-store v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@cinimod/use-store

Provides a simple way to bind and hook 🎣 your application with React's Context API.

Usage

Simple usage

You have your application running and need to put or retrieve something from Context.

import { Provider, useStore } from "@cinimod/use-store";

const MyComponent = () => {
  const { get } = useStore();

  // Should return <p>myValue</p>
  return <p>{get("mykey")}</p>
}

const Container = () => {
  // Provider automatically injects context
  <Provider initialState={{
    mykey: "myValue"
  }}>
    <MyComponent />
  </Provider>
}

Using with HOC

Using HOC to auto inject Context

import { withStore, useStore } from "@cinimod/use-store";

const MyComponent = () => {
  const { get } = useStore();

  // Should return <p>myValue</p>
  return <p>{get("mykey")}</p>
}

export default withStore({
  initialState: {
    mykey: "myValue"
  }
})(MyComponent)

Setting and Updating value to the context

import { withStore, useStore } from "@cinimod/use-store";

const MyComponent = () => {
  const { set, get } = useStore();

  return (
    // Should update value, when click theButton
    <>
      <button onClick={() => set("mykey", "newValue")}>theButton</button>
      <p>{get("mykey")}</p>
    </>
  )
}

export default withStore({
  mykey: "myValue"
})(MyComponent)
1.1.1

2 years ago

1.1.0

3 years ago

1.0.3-alpha.0

3 years ago

1.0.2-alpha.0

3 years ago

1.0.1-alpha.0

3 years ago

1.0.0-alpha.0

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago