Skip to content

How to refresh promise which depends on multiple variables #303

Description

@ApoorvGuptaAi

Raising an issue since I dont see clear documentation on this.

** Use case:
Given the following data in a component

const {data1, data2} = useCustomHook();

I need to run an async function getAsyncData(arg1, arg2) (which takes as arguments arg1=data1.id and arg2=data2.id) everytime data1 or data2 changes.

What i have come up with:

const memoizedAsync = useMemo(() => getAsyncData(data1.id, data2.id)), [data1, data2]);
const {data, isPending} = useAsync({promise: memoizedAsync});

Seems like there is a concept of promiseFn and watch values, which seems like they can do this in a more concise way, but couldnt find good documentation on what that would look like. (Another bug(#254) talks about how arrays cant be used in the watch value, so having a recommended solution would be good).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationDocumentation or usage example

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions