useStore

React hooks for the @corets/store package.

Source code is hosted on GitHub

yarn add @corets/use-store

This is a React integration for this package:

pageStore

useStore()

Use observable stores inside React components:

import React from "react"
import { createStore } from "@corets/store"
import { useStore } from "@corets/use-store"

const globalStore = createStore({ count: 0 })

const Example = () => {
  const store1 = useStore(() => ({ count: 0 }))
  const store2 = useStore(globalStore)
  
  // alternative syntax
  const [store, setStore] = useStore(globalStore).use()
  
  const increment = () => store1.set({ count: store1.get().count + 1 })
  
  return (
    <div>
      <button onClick={increment}>Count: {store1.get().count}</button>
    </div>
  )
}

Last updated