Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/toolkit/src/query/react/buildHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1471,6 +1471,7 @@ export function buildHooks<Definitions extends EndpointDefinitions>({
// if we had a last result and the current result is uninitialized,
// we might have called `api.util.resetApiState`
// in this case, reset the hook
let shouldResetData = false;
if (lastResult?.endpointName && currentState.isUninitialized) {
const { endpointName } = lastResult
const endpointDefinition = context.endpointDefinitions[endpointName]
Expand All @@ -1488,11 +1489,13 @@ export function buildHooks<Definitions extends EndpointDefinitions>({
})
)
lastResult = undefined
shouldResetData = true
}

// data is the last known good request result we have tracked - or if none has been tracked yet the last good result for the current args
let data = currentState.isSuccess ? currentState.data : lastResult?.data
if (data === undefined) data = currentState.data
else if(shouldResetData) data = undefined

const hasData = data !== undefined

Expand Down Expand Up @@ -1531,6 +1534,7 @@ export function buildHooks<Definitions extends EndpointDefinitions>({
// if we had a last result and the current result is uninitialized,
// we might have called `api.util.resetApiState`
// in this case, reset the hook
let shouldResetData = false;
if (lastResult?.endpointName && currentState.isUninitialized) {
const { endpointName } = lastResult
const endpointDefinition = context.endpointDefinitions[endpointName]
Expand All @@ -1547,11 +1551,13 @@ export function buildHooks<Definitions extends EndpointDefinitions>({
})
)
lastResult = undefined
shouldResetData = true
}

// data is the last known good request result we have tracked - or if none has been tracked yet the last good result for the current args
let data = currentState.isSuccess ? currentState.data : lastResult?.data
if (data === undefined) data = currentState.data
else if(shouldResetData) data = undefined

const hasData = data !== undefined

Expand Down
Loading