Using Forms in Next.js (Server Actions, Revalidating Data)

Using Forms in Next.js (Server Actions, Revalidating Data)

leerob

9 месяцев назад

131,116 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@27harisrehman
@27harisrehman - 28.11.2023 10:05

Please consider on updating the tutorials for Next14

Ответить
@bestchoice7431
@bestchoice7431 - 27.11.2023 17:00

Why are you using unstable useFormStatus and useFormState hooks since they are unstable?

Ответить
@flammea_
@flammea_ - 26.11.2023 00:30

If I get this right, this can only work without JavaScript, if you load the website with JavaScript and disable it after

Ответить
@stevebendersky2056
@stevebendersky2056 - 16.11.2023 19:54

Hey is this possible to use thhe useFormState with api route handler or fetch call ? as I dont use right now server actions in my app.

Ответить
@Grepsoft
@Grepsoft - 03.11.2023 19:27

It seems useFormState is only supported in the canary version. Has anyone been able to use this?

Ответить
@tarekahmed8159
@tarekahmed8159 - 01.11.2023 20:23

If PHP was a guy, what he would be feeling right now?

Ответить
@appstuff6565
@appstuff6565 - 31.10.2023 10:04

Hey there Lee, thanks for this. I wanted to ask how can i persist the typed in value in input field? EX: i have a page.tsx in signup folder -> signup/page.tsx , this one has the form in it and is server component. When i hit the sign up button, it goes to signup/route.ts with method post in <form method="post"/> . The route.ts for signup handles all the database management plus return NextResponse.redirect() etc as required. This is also server side. Both are server side. I just want to know how can i persist the input typed value so when i click the signup button i need to persist that typed in value and not make it disappear?

Ответить
@27sosite73
@27sosite73 - 25.10.2023 10:24

thank you

Ответить
@colepeterson9543
@colepeterson9543 - 20.10.2023 17:39

choice cut

Ответить
@kyle-andrewgovinder9902
@kyle-andrewgovinder9902 - 19.10.2023 20:33

Whoever drew up Lee's specs was very kind. Smart, endearingly charming, adorable as all hell

Ответить
@yashjha0007
@yashjha0007 - 18.10.2023 20:41

is there a reason why SubmitButton is a separate component instead of just being a part of AddForm. can we not use both useFormStatus and useFormState hooks in the same component?

Ответить
@flavienpensato9907
@flavienpensato9907 - 18.10.2023 00:50

Hello, very interesting but I wonder what about security? Do we have access to the request to now if users are authorized or not?

Ответить
@samuelchukwuzube8437
@samuelchukwuzube8437 - 16.10.2023 14:39

Hi, awesome tutorial as always. Please can I get the name of the Code editor's theme? Thanks

Ответить
@henriquetroiano5596
@henriquetroiano5596 - 15.10.2023 19:57

welcome to PHP, oops, next.

Ответить
@dhkim6672
@dhkim6672 - 09.10.2023 16:40

Since `aria-disabled` is used here, we must programmatically prevent clicking while pending state.

how can i handle this?

Ответить
@in43sh
@in43sh - 08.10.2023 19:33

instant subscription

Ответить
@xapper10
@xapper10 - 08.10.2023 13:18

can you make a video about caching in server and client components?

Ответить
@___ruthless
@___ruthless - 07.10.2023 23:22

app router tribe baby lets go

Ответить
@parhamtavakolian7562
@parhamtavakolian7562 - 07.10.2023 14:51

I'm new to nextjs13 , in react I was using react query to handle remote data coming from api and show isloading on screen and also optimistic UI , and I want to know does next 13 need any library to handle those functions or I just need to create fetch request in any server component I want. my current next project is a blog

Ответить
@MikeBritton
@MikeBritton - 07.10.2023 04:43

Thanks for this tutorial, Lee. Excellent job clarifying in simple terms the elements of server actions.

Ответить
@runonce
@runonce - 05.10.2023 17:29

Thanks, great vid! Is it possible to use GET instead of POST with server actions?

Ответить
@LordNases
@LordNases - 04.10.2023 00:59

you could be the most clear speaking person

Ответить
@morganleepierson
@morganleepierson - 04.10.2023 00:12

How would you recommend approaching submitting a form that relies on state being built up over time? For example: a form with multiple inputs including an input that builds an array of values through something like a multi-select input or an input collecting a list of emails?

Ответить
@Ty-mp4jr
@Ty-mp4jr - 03.10.2023 06:50

i would like to see binding extra arguments and formless use of server actions with starttransition as i feel there's a lot of interesting things that can be done with these methods.

Ответить
@jasonsouthin6981
@jasonsouthin6981 - 02.10.2023 18:13

Thanks for the video Lee !

Ответить
@ishakimanuel3513
@ishakimanuel3513 - 02.10.2023 13:22

is adding some data using hidden input are recommended ways by nextjs team? is it a best practices or i can try another way? why just not passing the hidden data in initial argument of form hooks , it looks like more simpler rather than adding additional html element

Ответить
@MichaelPresecan
@MichaelPresecan - 01.10.2023 20:02

In the latest react useFormState is not present

Ответить
@wolandmargarita
@wolandmargarita - 30.09.2023 19:35

Is there an LLM that is trained on these latest features? I am trying to learn and ChatGPT is a huge help but it knows nothing of this.

Ответить
@portalplays3760
@portalplays3760 - 30.09.2023 18:58

Can you do an example where JavaScript is disabled, server side validation fails, and we need to show an error state to the user. This doesn't seem to work in the example provided.

Ответить
@mystupidbrain5299
@mystupidbrain5299 - 29.09.2023 07:38

If this was a login form, how would you handle session storage?

Ответить
@jeffz7035
@jeffz7035 - 28.09.2023 22:00

Are server actions still technically experimental?

Ответить
@FatihAltnok
@FatihAltnok - 28.09.2023 20:14

Great tip, aria-disabled instead of disabled!

Ответить
@samarnagar9699
@samarnagar9699 - 28.09.2023 19:18

can you make tutorial for how to intigrate and work with postgres with next js without express

Ответить
@Sorkstryparen
@Sorkstryparen - 28.09.2023 13:02

Super great and educational videos you do! Keep it up!

Ответить
@RaducuGabriel
@RaducuGabriel - 28.09.2023 08:41

i don't get why you have use client on top

Ответить
@76900aakhtar
@76900aakhtar - 28.09.2023 02:53

This is good. What about validations message when typing. That’s the real use case

Ответить
@blazi_0
@blazi_0 - 27.09.2023 17:10

Please no one is talking on the revalidate tag, how can u use it in this case??

Ответить
@giovannitonussi3746
@giovannitonussi3746 - 27.09.2023 03:57

Thats very nice and useful. But I ask aren't we delegating too much responsibility to the "behind the curtains"?

Ответить
@gmzi
@gmzi - 26.09.2023 20:48

thanks lee, this is awesome. I'm just wondering how to clear the text input after a new todo has been created. So much cool stuff to try out!!!

Ответить
@robgioeli
@robgioeli - 26.09.2023 19:36

I genuinely love Next. It has changed my life financially and has made working with the web intuitive.

Ответить
@solaaar3
@solaaar3 - 26.09.2023 17:18

i'm getting an error while running the dev server: VercelPostgresError - 'missing_connection_string': You did not supply a 'connectionString' and no 'POSTGRES_URL' env var was found.

Ответить
@didardev
@didardev - 26.09.2023 16:08

nice video, what if we have a modal and we want to close it after the server action is done and returned value from server, ?

Ответить
@rockNbrain
@rockNbrain - 26.09.2023 14:31

Great job guys, I'd love if server get stable and I will heavly use it !!

Ответить
@HoxyzOG
@HoxyzOG - 26.09.2023 14:09

When cloning the project locally and filling in my vercel database credentials I get "Error: db error: ERROR: relation "todos" does not exist

Caused by:
ERROR: relation "todos" does not exist"

And when im tryting to deploy this straight from the template to vercel It also won't build.
Type error: '"react-dom"' has no exported member named 'experimental_useFormState'. Did you mean 'experimental_useFormStatus'?
1 | 'use client'
2 |
> 3 | import { experimental_useFormState as useFormState } from 'react-dom'
| ^
4 | import { experimental_useFormStatus as useFormStatus } from 'react-dom'
5 | import { createTodo } from '@/app/actions'
6 |
error Command failed with exit code 1.

Something broken with the template?

Ответить
@rijkvanwel
@rijkvanwel - 26.09.2023 12:46

I know documentation is being worked on, but could you describe in 1-2 lines what experimental_useFormState does exactly?

Ответить
@user-il8jv5gh1u
@user-il8jv5gh1u - 26.09.2023 11:20

Real shame that useFormState only works in client components - IMO this prevents proper progressive enhancement with javascript disabled (i.e. we can't return errors from the action). Remix's useActionData allows this to happen.

Ответить
@EvHaus
@EvHaus - 26.09.2023 09:29

This is great! Can you do a follow up with some more advanced stuff? Like, how do I handle optimistic updates & failures/rollbacks, how do I ensure my TODOs mutation state is synced across all pages/components that might need it, how can I update TODOs state from within the app code (not as part of a form submission). In other words -- is it possible to use this new paradigm to replace most of what Redux does?

Ответить
@GeorgerSays
@GeorgerSays - 26.09.2023 07:07

Thanks, very helpful video. How would you go about clearing the input after submitting with server actions?

Ответить
@shadowfaxenator
@shadowfaxenator - 26.09.2023 04:39

When JS is disabled we don't get action returns. in state

Ответить
@81NARY
@81NARY - 26.09.2023 03:46

Hey, could you maybe shed some light on Auth + XSRF on this? As it's submitting a form and if cookies are used for Auth, this would be vulnerable to XSRF attacks, right?

Ответить