W
Wasp5mo ago
Rômullo

how to Re-hydrate query data ?

I want to call the query again every time my currentPage changes, but the way it's coded in the print example, the pages re-renders in a weird way and my pagination component doesn't work as expected.
6 Replies
kapa.ai
kapa.ai5mo ago
Hi @Rômullo. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Hmm, I don't know enough to give you a confident answer yet. However, in Wasp, you can use the useQuery hook to make your component reactive. This means that React will re-render the component every time the Query changes. Wasp automatically refreshes Queries whenever the data is modified. This might be helpful in your case where you want to re-fetch the data every time the currentPage changes. Here is an example of how to use the useQuery hook in Wasp:
import {
useQuery,
getTask,
} from 'wasp/client/operations'

const TaskPage = ({ id }) => {
const { data: task } = useQuery(getTask, { id })

// ... rest of the component
}
import {
useQuery,
getTask,
} from 'wasp/client/operations'

const TaskPage = ({ id }) => {
const { data: task } = useQuery(getTask, { id })

// ... rest of the component
}
In this example, the useQuery hook is used to fetch a task. Every time the id prop changes, the useQuery hook will re-fetch the task. For more detailed information, you can refer to the Wasp documentation (https://wasp-lang.dev/docs/tutorial/queries#invoking-the-query-on-the-frontend). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Rômullo, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Rômullo
RômulloOP5mo ago
full page code
No description
Rômullo
RômulloOP5mo ago
when i click on another page, setCurrentPage is called, query is called, new data is rendered
No description
MEE6
MEE65mo ago
Wohooo @Rômullo, you just became a Waspeteer level 1!
Rômullo
RômulloOP5mo ago
but the page blinks, there is any way to prevent this ?
IamIconLiving
IamIconLiving5mo ago
"blinks" - as in the data is being loaded? you need to handle your loading state probably, while the data is being loaded?
Want results from more Discord servers?
Add your server