useStorePath returns the value at the given path on your store, keeps your Component synced with any changes, and provides a convenient setter to update the value.
npm install --save @app-elements/use-store-path
import { useStorePath } from '@app-elements/use-store-path'
import createStore from 'atom'
const store = createStore([], { nested: { count: 0 } })
const Counter = (props) => {
const [count, setCount] = useStorePath(store, 'nested.count') // Or, `['nested', 'count']` also works
return (
<p>Count: {count}</p>
<button onClick={() => setCount(count + 1)}>+1</button>
)
}
Prop | Type | Default | Description |
---|---|---|---|
store |
Object | None | An (atom) store instance |
path |
_String | Array_ | None |