Describe the bug#
In my React Native app, the Portfolio screen displays a list of investment cards. Tapping on any card navigates to the InvestmentDetails screen, where a user can sell the investment using the useRequestInvestmentSell hook.
β
Expected Behavior:
After submitting a sell request:
1- InvestmentDetails screen updates:
2- Portfolio screen updates:
- The sold investment card displays a flag indicating a pending sell request
To achieve this, I'm invalidating the following queries after submission:
INVESTMENT_SELL_REQUESTS (for the request list)
CUSTOMER_BANK_INVESTMENTS_DETAILS
CUSTOMER_BANK_INVESTMENTS (cards rendered in the Portfolio)
β Actual Behavior:
When navigating back to the Portfolio screen, the data does not update as expected.
The only workaround that currently works is manually calling invalidateQueries(CUSTOMER_BANK_INVESTMENTS) inside a useFocusEffect() hook on the Portfolio screen β but this feels like a hack and is not ideal for performance or code cleanliness. π
export const useRequestInvestmentSell = () => {
const queryClient = useQueryClient()
return useMutation(bankApi.requestInvestmentSell, {
onSuccess: () => {
queryClient.invalidateQueries(INVESTMENT_SELL_REQUESTS)
queryClient.invalidateQueries(CUSTOMER_BANK_INVESTMENTS_DETAILS)
queryClient.invalidateQueries(CUSTOMER_BANK_INVESTMENTS)
},
})
}
Your minimal, reproducible example#
Steps to reproduce#
Expected behavior#
How often does this bug happen?#
None
Screenshots or Videos#
No response
Platform#
Tanstack Query adapter#
None
TanStack Query version#
TypeScript version#
No response
Additional context#
No response
Thank you for filing this issue, but we need more information before looking into this.
Specifically, a minimal, standalone, runnable reproduction is needed - preferably with codesandbox or stackblitz. If your issue is TypeScript related, prefer a TypeScript playground.
We'll close this issue for now, but we'll certainly re-open it if there is a proper reproduction.