(current: TSource)
| 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 | // We're deliberately not using idiomatic destructuring for the hook here. |
| 11 | // Accessing the state value as an array element prevents TypeScript from generating unnecessary helpers in the resulting code. |
| 12 | // For further details, please refer to mobxjs/mobx#3842. |
| 13 | const res = useState(() => observable(current, {}, { deep: false }))[0] |
| 14 | runInAction(() => { |
| 15 | Object.assign(res, current) |
| 16 | }) |
| 17 | return res |
| 18 | } |
searching dependent graphs…