1 | import { observable } from "mobx"
|
2 | import { useState } from "react"
|
3 |
|
4 | import { useDeprecated } from "./utils/utils"
|
5 | import { useAsObservableSource } from "./useAsObservableSource"
|
6 |
|
7 | export function useLocalStore<TStore extends Record<string, any>>(initializer: () => TStore): TStore
|
8 | export function useLocalStore<TStore extends Record<string, any>, TSource extends object>(
|
9 | initializer: (source: TSource) => TStore,
|
10 | current: TSource
|
11 | ): TStore
|
12 | export 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 |