-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.d.ts
60 lines (56 loc) · 1.28 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import type { Store, StoreValue } from 'nanostores'
type StoreKeys<T> = T extends { setKey: (k: infer K, v: any) => unknown }
? K
: never
export interface UseStoreOptions<SomeStore> {
/**
* Will re-render components only on specific key changes.
*/
keys?: StoreKeys<SomeStore>[]
}
/**
* Subscribe to store changes and get store’s value.
*
* Can be user with store builder too.
*
* ```js
* import { useStore } from 'nanostores/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<SomeStore extends Store>(
store: SomeStore,
options?: UseStoreOptions<SomeStore>
): StoreValue<SomeStore>
/**
* Batch React updates. It is just wrap for React’s `unstable_batchedUpdates`
* with fix for React Native.
*
* ```js
* import { batch } from 'nanostores/preact'
*
* React.useEffect(() => {
* let unbind = store.listen(() => {
* batch(() => {
* forceRender({})
* })
* })
* })
* ```
*
* @param cb Callback to run in batching.
*/
export function batch(cb: () => void): void