Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mobx-react-lite] Workaround for typescript issue #43541 #3842

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/short-hats-move.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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]
mweststrate marked this conversation as resolved.
Show resolved Hide resolved
runInAction(() => {
Object.assign(res, current)
})
Expand Down