Skip to content

keepPreviousData does not preserve data #1002

@andyvanhelsing

Description

@andyvanhelsing

Setting keepPreviousData option to true does not preserve previous stale data when the query key changes but before refetch is called, as described in #419. There have been some API changes from v1 to v2 so it is possible that this is intentional but not well documented. Sample code:

const [dateRange, setDateRange] = React.useState([today, today]);
    const {data, latestData, resolvedData, error, refetch, isFetching} = usePaginatedQuery(
        [dateRange[0], dateRange[1]], // should not refetch when date range changes
        searchFx,
        {enabled: false, keepPreviousData: true} // have tried with and without keepPreviousData
    );

// only search when the button is clicked
return <Button onClick={refetch}>Search</Button>

A similar configuration was working in v1.5.10

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