Skip to content

RTK Query: selectFromResult must return an object (docs could be more clear on this) #3650

@gillycheesesteak

Description

@gillycheesesteak

Edited based on discussion below

The docs could be more clear about the expected/required return value from selectFromResult (and maybe reasons for those expectations)

Original issue:

As the title states, if the selectFromResult function returns a value directly, it results in the following error:

rtk-query-react.esm.js:318 Uncaught TypeError: Cannot read properties of undefined (reading 'data')

The issue appears to stem from useQuery relying on useQueryState which returns undefined after a few renders, causing the above error on this line:

const queryStateResults = useQueryState(arg, {
selectFromResult:
arg === skipToken || options?.skip
? undefined
: noPendingQueryStateSelector,
...options,
})
const { data, status, isLoading, isSuccess, isError, error } =
queryStateResults

This behavior may be intentional - if so, the docs should be updated to reflect that.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions