MCPcopy
hub / github.com/mobxjs/mobx / useAsObservableSource

Function useAsObservableSource

packages/mobx-react-lite/src/useAsObservableSource.ts:5–18  ·  view source on GitHub ↗
(current: TSource)

Source from the content-addressed store, hash-verified

3import { useState } from "react"
4
5export 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}

Callers 5

useLocalStoreFunction · 0.90
CounterFunction · 0.90
ChildFunction · 0.90
hooks.test.tsxFile · 0.90

Calls 2

useDeprecatedFunction · 0.90
observableFunction · 0.90

Tested by 2

CounterFunction · 0.72
ChildFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…