Skip to content

Conversation

43081j
Copy link
Collaborator

@43081j 43081j commented Aug 27, 2025

Outside of typescript, we can already do this if resetOnExecute: false.

If it is true, we cause a maximum stack call exception since we're setting ref.value = ref (infinitely).

This updates the source so you can pass a ref in and we turn it into a value before using it as such.

This means you can now use your own ref:

const myRef = shallowRef(200);
useAsyncState(asyncPromise, myRef);
// some time later, `myRef.value` is whatever `asyncPromise` resolved to

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Aug 27, 2025
@dosubot dosubot bot added the enhancement New feature or request label Aug 27, 2025
Outside of typescript, we can already do this but we cause a maximum
stack call exception since we're setting `ref.value = ref` (infinitely).

This updates the source so you can pass a ref in and we turn it into a
value before using it as such.

This means you can now use your own ref:

```ts
const myRef = shallowRef(200);
useAsyncState(asyncPromise, myRef);
// some time later, `myRef.value` is whatever `asyncPromise` resolved to
```
Copy link

pkg-pr-new bot commented Aug 27, 2025

Open in StackBlitz

@vueuse/components

npm i https://pkg.pr.new/@vueuse/components@4992

@vueuse/core

npm i https://pkg.pr.new/@vueuse/core@4992

@vueuse/electron

npm i https://pkg.pr.new/@vueuse/electron@4992

@vueuse/firebase

npm i https://pkg.pr.new/@vueuse/firebase@4992

@vueuse/integrations

npm i https://pkg.pr.new/@vueuse/integrations@4992

@vueuse/math

npm i https://pkg.pr.new/@vueuse/math@4992

@vueuse/metadata

npm i https://pkg.pr.new/@vueuse/metadata@4992

@vueuse/nuxt

npm i https://pkg.pr.new/@vueuse/nuxt@4992

@vueuse/router

npm i https://pkg.pr.new/@vueuse/router@4992

@vueuse/rxjs

npm i https://pkg.pr.new/@vueuse/rxjs@4992

@vueuse/shared

npm i https://pkg.pr.new/@vueuse/shared@4992

commit: 2e2ba51

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Aug 27, 2025
@43081j 43081j added this pull request to the merge queue Aug 27, 2025
Merged via the queue into main with commit e38e8d9 Aug 27, 2025
10 checks passed
@43081j 43081j deleted the async-state-refs branch August 27, 2025 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request lgtm This PR has been approved by a maintainer size:S This PR changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants