#Do you use server actions to get data in client components?

6 messages · Page 1 of 1 (latest)

pliant violet
#

I'm curious how members of this channel use server actions, specifically if you use server actions to fetch data inside client components.

  • do you call them in SWR, ReactQuery or you use useTransition() hook?
  • how do you transfer data and objects like Error from action to client component?

Any discussion and thoughts about server actions are welcome!

empty zincBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

granite kiln
#

You don't have to use server actions to do that, if you're running code from a server component you can just fetch an async function

server.ts

"use server";

const getData = async () => {
  return dataFromSomewhere;
}

page.tsx

"use server";

const Page = async() => {
  const data = await getData();

  return (
    <div>JSON.stringify(data)</div>
  )
}
#

oh nvm client components

#

I'd usually just pass data from a server component as a prop

#

so I can get the data on the server and then use it in the client without having to wait for data to load clientside