From eecf67c9045987e4c8d6f3eda106b27fbf48c7c6 Mon Sep 17 00:00:00 2001 From: Roman Vyakhirev Date: Thu, 7 Mar 2024 15:31:14 +0100 Subject: [PATCH] Workaround for typescript issue #43541 --- .changeset/short-hats-move.md | 5 +++++ packages/mobx-react-lite/src/useAsObservableSource.ts | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 .changeset/short-hats-move.md diff --git a/.changeset/short-hats-move.md b/.changeset/short-hats-move.md new file mode 100644 index 000000000..edd79785f --- /dev/null +++ b/.changeset/short-hats-move.md @@ -0,0 +1,5 @@ +--- +"mobx-react-lite": patch +--- + +Prevent warnings when using `mobx-react-lite` with Rollup diff --git a/packages/mobx-react-lite/src/useAsObservableSource.ts b/packages/mobx-react-lite/src/useAsObservableSource.ts index 5b83a75fb..ffda077f6 100644 --- a/packages/mobx-react-lite/src/useAsObservableSource.ts +++ b/packages/mobx-react-lite/src/useAsObservableSource.ts @@ -7,7 +7,10 @@ export function useAsObservableSource(current: TSource): 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." ) - const [res] = useState(() => observable(current, {}, { deep: false })) + // We're deliberately not using idiomatic destructuring for the hook here. + // Accessing the state value as an array element prevents TypeScript from generating unnecessary helpers in the resulting code. + // For further details, please refer to mobxjs/mobx#3842. + const res = useState(() => observable(current, {}, { deep: false }))[0] runInAction(() => { Object.assign(res, current) })