1 | import { useDeprecated } from "./utils/utils"
|
2 | import { observable, runInAction } from "mobx"
|
3 | import { useState } from "react"
|
4 |
|
5 | export function useAsObservableSource<TSource extends object>(current: TSource): TSource {
|
6 | if ("production" !== process.env.NODE_ENV)
|
7 | useDeprecated(
|
8 | "[mobx-react-lite] 'useAsObservableSource' is deprecated, please store the values directly in an observable, for example by using 'useLocalObservable', and sync future updates using 'useEffect' when needed. See the README for examples."
|
9 | )
|
10 |
|
11 |
|
12 |
|
13 | const res = useState(() => observable(current, {}, { deep: false }))[0]
|
14 | runInAction(() => {
|
15 | Object.assign(res, current)
|
16 | })
|
17 | return res
|
18 | }
|