UNPKG

961 BPlain TextView Raw
1import { observable } from "mobx"
2import { useState } from "react"
3
4import { useDeprecated } from "./utils/utils"
5import { useAsObservableSource } from "./useAsObservableSource"
6
7export function useLocalStore<TStore extends Record<string, any>>(initializer: () => TStore): TStore
8export function useLocalStore<TStore extends Record<string, any>, TSource extends object>(
9 initializer: (source: TSource) => TStore,
10 current: TSource
11): TStore
12export function useLocalStore<TStore extends Record<string, any>, TSource extends object>(
13 initializer: (source?: TSource) => TStore,
14 current?: TSource
15): TStore {
16 if ("production" !== process.env.NODE_ENV) {
17 useDeprecated(
18 "[mobx-react-lite] 'useLocalStore' is deprecated, use 'useLocalObservable' instead."
19 )
20 }
21 const source = current && useAsObservableSource(current)
22 return useState(() => observable(initializer(source), undefined, { autoBind: true }))[0]
23}
24
\No newline at end of file