Filtering and search in RSC

I'm trying to implement filtering and searching in server components but its kinda slow, the way im doing it is i redirect to a new url with searchParams and then filter the data in the page.tsx which is a server component, Here's the code: thats from the child client component
const searchParams = new URLSearchParams(filtersParams);
router.replace(`/ticketing?${searchParams}`);
const searchParams = new URLSearchParams(filtersParams);
router.replace(`/ticketing?${searchParams}`);
and this is the page.tsx
{tickets.watcherTickets
.filter((ticket) => {
if (
ticket.currentStage?.stageAssignedTo !== user.userID &&
(!searchParams.type ||
ticketTemplates.find((template) => template.ticketTemplateID === ticket.ticketTemplateID)
?.templateTitle === searchParams.type) &&
(!searchParams.status || ticket.currentStage?.stageStatus === searchParams.status) &&
(!searchParams.dateFrom ||
isWithinInterval(parseISO(ticket.currentStage?.stageAssignedDate), {
start: parseISO(searchParams.dateFrom),
end: parseISO(searchParams.dateTo),
}))
) {
return true; // Include this ticket in the result
}
return false; // Exclude this ticket from the result
})
{tickets.watcherTickets
.filter((ticket) => {
if (
ticket.currentStage?.stageAssignedTo !== user.userID &&
(!searchParams.type ||
ticketTemplates.find((template) => template.ticketTemplateID === ticket.ticketTemplateID)
?.templateTitle === searchParams.type) &&
(!searchParams.status || ticket.currentStage?.stageStatus === searchParams.status) &&
(!searchParams.dateFrom ||
isWithinInterval(parseISO(ticket.currentStage?.stageAssignedDate), {
start: parseISO(searchParams.dateFrom),
end: parseISO(searchParams.dateTo),
}))
) {
return true; // Include this ticket in the result
}
return false; // Exclude this ticket from the result
})
is there another way to do it? maybe my internet is slow so its taking couple of seconds to go to the new url
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server