import type { Store, StoreValue } from 'nanostores' type StoreKeys = T extends { setKey: (k: infer K, v: any) => unknown } ? K : never export interface UseStoreOptions { /** * Will re-render components only on specific key changes. */ keys?: StoreKeys[] /** * Enable SSR support. Set `initial` when store's initial value is the same * on server and client, or provide a function to return the server store * state for advanced cases. */ ssr?: 'initial' | (() => StoreValue) | false } /** * 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 * } else { * return * } * } * ``` * * @param store Store instance. * @returns Store value. */ export function useStore( store: SomeStore, options?: UseStoreOptions ): StoreValue /** * 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