Next.js Discord

Discord Forum

excessive function invocations

Unanswered
Sage Thrasher posted this in #help-forum
Open in Discord
Sage ThrasherOP
Currently im using server actions for getting data due to how much easier it is than route handlers. I know you should only use this for writing data, however considering both use vercel function invocations, i dont see why using the quicker option would make any difference.

i currently user react-query to make fetches on the client. my app has only been live for around a month and I've already made 1.2mil function invocations, and i have no clue at all how to minimise these?

Example of how I fetch data on the client. I do most the fetching on the client so i can have separate loaders (skeletons) for different aspects of the page.
const { data: trendingTags } = useQuery({
  queryKey: ['trendingTags'],
  queryFn: () => fetchTrendingTags({ limit: 8 })
})

2 Replies

Sage ThrasherOP
what im essentially asking is, what are best practices when it comes to fetching, and how can i limit function invocations as much as possible when im fetching them on the client
@Sage Thrasher what im essentially asking is, what are best practices when it comes to fetching, and how can i limit function invocations as much as possible when im fetching them on the client
Asiatic Lion
did ya get any feedback on this? im seeing massive Function Invocations on my app too and looking at ways of how to optimise. I use server actions for everything because its just so easy to use