UNPKG

994 BJavaScriptView Raw
1import { useDeprecated } from "./utils/utils";
2import { observable, runInAction } from "mobx";
3import { useState } from "react";
4export function useAsObservableSource(current) {
5 if ("production" !== process.env.NODE_ENV)
6 useDeprecated("[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.");
7 // We're deliberately not using idiomatic destructuring for the hook here.
8 // Accessing the state value as an array element prevents TypeScript from generating unnecessary helpers in the resulting code.
9 // For further details, please refer to mobxjs/mobx#3842.
10 var res = useState(function () { return observable(current, {}, { deep: false }); })[0];
11 runInAction(function () {
12 Object.assign(res, current);
13 });
14 return res;
15}
16//# sourceMappingURL=useAsObservableSource.js.map
\No newline at end of file