Once on client side, fetch data from within server actions that return components #1305
roggc
started this conversation in
Show and tell
Replies: 1 comment
-
See some examples: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
My idea or suggestion is this, to use server actions, once on the client side, to fetch data and return components (Client or not). I have tried with Waku and it's possible, without any errors or warnings on the console. For example let's say we have a home page (server component) like this:
Then
HomePage
will be like this:greeting
is a server action that performs a fetching of data and returns a client component with the fetched data passed as prop to the component:Greeting
is this case a component (Client or not):But an even better approach would be to use non blocking server actions, that is, instead of awaiting in the fetching of data, pass the promise to the returned component by the server action.
This works and the advantage respect the first approach (the blocking one), is that in this case the 'hey' content appears immediately on the screen without waiting for the promise to fulfill.
What do you think of this idea or approach? Isn't great that
Waku
allows to implement it in a straightforward way without any errors on Console or warnings? Would you use this approach? Any comments are appreciated. Thanks.//edit
In the case of the promise resolving to an array, if we want to make use of the
map
function in the array resolved, we can use theuse
function from React://edit 2
An evolution of this last approach is to define a component
SuspenseWithUse
like this:And use it in our
GreetingPromise
client component:Beta Was this translation helpful? Give feedback.
All reactions