@nanostores/react
Advanced tools
Comparing version 0.1.3 to 0.1.4
import { MapStore, Store, StoreValue } from 'nanostores' | ||
export interface UseStoreOptions< | ||
SomeStore, | ||
Key extends string | number | symbol | ||
> { | ||
type AllKeys<T> = T extends any ? keyof T : never | ||
export interface UseStoreOptions<SomeStore, Key extends PropertyKey> { | ||
keys?: SomeStore extends MapStore ? Key[] : never | ||
@@ -22,3 +21,3 @@ } | ||
* let page = useStore(router) | ||
* if (page.router === 'home') { | ||
* if (page.route === 'home') { | ||
* return <HomePage /> | ||
@@ -34,5 +33,34 @@ * } else { | ||
*/ | ||
export function useStore<SomeStore extends Store>( | ||
store: SomeStore | ||
): StoreValue<SomeStore> | ||
/** | ||
* Subscribe to store changes and get store’s value. | ||
* | ||
* Can be user with store builder too. | ||
* | ||
* ```js | ||
* import { useStore } from 'nanostores/react' | ||
* | ||
* import { router } from '../store/router' | ||
* | ||
* export const Layout = () => { | ||
* let page = useStore(router, { keys: [ 'route' ] }) | ||
* if (page.route === 'home') { | ||
* return <HomePage /> | ||
* } else { | ||
* return <Error404 /> | ||
* } | ||
* } | ||
* ``` | ||
* | ||
* @param store Store instance. | ||
* @param options Subscription configuration. | ||
* `keys` attribute controls which store value properties will be returned and listened to. | ||
* @returns Store value. | ||
*/ | ||
export function useStore< | ||
SomeStore extends Store, | ||
Key extends keyof StoreValue<SomeStore> | ||
Key extends AllKeys<StoreValue<SomeStore>> | ||
>( | ||
@@ -39,0 +67,0 @@ store: SomeStore, |
{ | ||
"name": "@nanostores/react", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "React integration for Nano Stores, a tiny state manager with many atomic tree-shakable stores", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6744
8
136