@logux/state
Version:
A tiny (152 bytes) state manager for React/Preact/Vue/Svelte with many atomic tree-shakable stores
26 lines (24 loc) • 584 B
TypeScript
import { Store } from '../create-store/index.js'
/**
* Subscribe to store changes and get store’s value.
*
* Can be user with store builder too.
*
* ```js
* import { useStore } from '@logux/state/preact'
* import { router } from '../store/router'
*
* export const Layout = () => {
* let page = useStore(router)
* if (page.router === 'home') {
* return <HomePage />
* } else {
* return <Error404 />
* }
* }
* ```
*
* @param store Store instance.
* @returns Store value.
*/
export function useStore<Value extends any>(store: Store<Value>): Value