1. 22
    Display Pending UI with React useFormStatus Hook (experimental)
    1m 44s

Display Pending UI with React useFormStatus Hook (experimental)

Ben Patton
InstructorBen Patton
Share this video with your friends

Social Share Links

Send Tweet
Published 9 months ago
Updated 8 months ago

With the new experimental_useFormStatus hook, we can add pending ui to indicate a mutation is in process.

Instructor: [0:00] As we're working on making our user experience better for adding a customer, one of the things we've noticed is that when we look at our modal, whenever we click onsubmit(), we have no feedback. One of the things we can now do is add a new experimental hook from React called useFormStatus.

[0:17] The way that you would typically expect to do this is to add your import here, and then you would just get your hook here, and it gives us a object. We would get pending from that, useFormStatus, and then you would think you could come to your button and just add a disabled.

[0:36] Then add your text here. If it's pending, we want to say loading, else we want to say submit. But this doesn't work, and the reason for this is that the current way that the API is set up, you have to use the useFormStatus in its own component.

[0:53] We need to take this button and make its own component, and instead of this loading, let's just make this our spinner icon. Then we can just bring our hook down to that new component. Now, we just add our submit button. And so, now, if we come back to our application, let's add Dwight.

[1:18] Now we click submit. We get our loading icon. Dwight was added. We can check our terminal, scroll up a bit, and we see, yep, Dwight was added, and Dwight is here.

[1:29] In review, we added the new experimental useFormStatus hook from React. To use the hook, we had to create a new component that made use of the hook, and then add that component into our form. Now, we're able to give our user good feedback. Whenever they click submit, they get a loading state.

egghead
egghead
~ 20 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today