List In UI Not Showing New Data Until Refreshed tRPC React-Query
II am showing a shopping list of items. I can create new items from web form but they don't show in the page until I refresh or click off the page and then click back on the webpage. Am I using react-quest / tRPC queries properly?
https://stackoverflow.com/questions/74411386/list-in-ui-not-showing-new-data-until-refreshed-trpc-react-query
Stack Overflow
List In UI Not Showing New Data Until Refreshed: tRPC React-Query
I am trying to use tRPC (which wraps react-query) to get data into a shopping list. I think the problem may be that I am querying for my shoppingList/shoppingListId and item's separately. Maybe thi...
5 Replies
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
@Micheaaa thanks! I ended up deconstructing
refetch
off the call that created my trpc query and then just called refetch()
and that seemed to do the trick.Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Do you mind showing how you did this in your code? I'm having trouble invalidating or refetching queries upon successful mutation as well
const utils = trpc.useContext()
const students = trpc.student.getAll.useQuery()
const addStudentTRPC = trpc.student.add.useMutation({
onSuccess() {
utils.student.getAll.invalidate()
},
})
This invalidation is currently not working for me@theFern I used
refetch
which I got off const {data, refetch}=trpc.item.getAllFromList.useQuery(inp)
https://github.com/currenthandle/shopping-list/commit/caefc9cc502224de8eec38ae8f9b994ac502b0ca#diff-538c0d6adcaf0f636917511d3a6052299d73fcddac727c29a9e315f4adf6b121R25
which I then triggeded in the onSuccess of my mutate event
https://github.com/currenthandle/shopping-list/commit/caefc9cc502224de8eec38ae8f9b994ac502b0ca#diff-538c0d6adcaf0f636917511d3a6052299d73fcddac727c29a9e315f4adf6b121R33
I ended up taking this out and updating the UI state manually to avoid querying all the time unnecessarily
https://github.com/currenthandle/shopping-list/commit/4be8fb28d372cd5b98241b0d8376e07477b948f9