Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Issue #236]: Server action example #341
base: main
Are you sure you want to change the base?
[Issue #236]: Server action example #341
Changes from 1 commit
6967ae3
ed73953
9ce1598
ab81b10
46146f1
6b6f021
a7c722d
3b60b3c
7eeaf44
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be helpful for the example to also demonstrate how to test the page, as well as render it in Storybook.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can give tests and storybook a shot when we decide on how we want to construct these example(s)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there alternative approaches where the entire page doesn't need opted out of being a server component?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No expert at this, but I believe you can have server only forms - but then you can't demo the client hooks like
useFormStatus
anduseFormState
(not that these hooks have to be used with a server action). For a server-based form, instead ofuseFormState
you would just call the server action function directly in the form's action attribute - but you can't do any user input in textboxes and such.I'm not sure if another server (second) example makes sense for comparison? IE - Just call a server action from a server component page - and pass the resulting data down into a client component that displays it.
Just wanted to get things started on this cause I think it would have helped on our project if we had these examples.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think one alternative is to have a separate component for the part that depends on the client-only hook. I think for most forms it's likely just the submit button, so it might be something like:
I think that would then allow the page to be a server component with a small client-side island.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sawyerh this makes sense and we can try this - but we won't be able to demo
useFormState
without making the form (and text inputs) client components. I updated it to use a page but with a client form component withuseFormState
.It can work with the form in a server component (with some eslint rules turned off (
no-misused-promise
). Lmk if we want multiple examples or something.