Skip to content

onResolve use old callback #32

@charleyw

Description

@charleyw

Hi there,
Thanks for provider this awesome lib, l like the api very much.

I have a situation that in a list page, there will be 3 api calls:

  1. loads all the list items when page loads.
  2. batch update selected items status, when success should reload the list items
  3. another batch update action.

I use following code to implement above logic

const {data, isLoading, reload} = useAsync({promiseFn: loadAllItems, query: query, watch: "...."})

// query is from url params, there is a filter bar to update this. i use watch update auto reload.

const handleBatchUpdateSuccess = () => {
   mesasge.info("success")
   reload()
}

const {run: batchUpdate} = useAsync({deferFn: batchUpdateItems, onResolve: handleBatchUpdateSuccess})

const {run: anotherBatchUpdate} = useAsync({deferFn: anotherBatchUpdateItems, onResolve: handleBatchUpdateSuccess})

Problems occurs as following:

  1. Refresh the page, so all the data reloads, we say it's the filter1
  2. Change the filter, so the data reloaded, we say it's the filter2
  3. use the batchUpdate action, then page reload again. but the reload is using the filter1 instead of filter2.

I've tried to not use onResolve, but using the onEffect to watch the batchUpdateLoading to fire the same callback(handleBatchUpdateSuccess), and it's act as expected.

So i guess whether there are some machism that cached the onResolve callback.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions