Skip to content

Commit

Permalink
fix: Workaround for typescript issue #43541 (#3842)
Browse files Browse the repository at this point in the history
  • Loading branch information
r0b1n committed Mar 28, 2024
1 parent 5142574 commit 7bbb523
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/short-hats-move.md
@@ -0,0 +1,5 @@
---
"mobx-react-lite": patch
---

Prevent warnings when using `mobx-react-lite` with Rollup
5 changes: 4 additions & 1 deletion packages/mobx-react-lite/src/useAsObservableSource.ts
Expand Up @@ -7,7 +7,10 @@ export function useAsObservableSource<TSource extends object>(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)
})
Expand Down

0 comments on commit 7bbb523

Please sign in to comment.