@hurum/react
v0.0.2
Published
React bindings for @hurum/core — useStore, StoreProvider, withProvider
Readme
@hurum/react
Warning — Hurum is in early development (
0.0.x). APIs may change without notice. Do not use in production yet.
React bindings for @hurum/core.
Install
npm install @hurum/core @hurum/reactRequires React 18+.
API
useStore(Definition)
Access a store instance. Inside a StoreProvider, returns the scoped instance. Outside, falls back to a singleton.
import { useStore } from '@hurum/react'
function Counter() {
const store = useStore(CounterStore)
return <button onClick={() => store.send.increment()}>
{store.state.count}
</button>
}<StoreProvider>
Provide a scoped store instance to a subtree.
import { StoreProvider } from '@hurum/react'
<StoreProvider of={CounterStore}>
<Counter />
</StoreProvider>
// or with options
<StoreProvider of={CounterStore} initialState={{ count: 10 }}>
<Counter />
</StoreProvider>
// or with an existing instance
<StoreProvider of={CounterStore} store={myInstance}>
<Counter />
</StoreProvider>withProvider(Definition, Component)
HOC that wraps a component with a StoreProvider.
import { withProvider } from '@hurum/react'
const CounterPage = withProvider(CounterStore, Counter)Docs
License
MIT
