Using Hooks for Handling Forms
In the previous chapter, we learned how to use Hooks for Data Fetching and React Suspense for showing a fallback while waiting on the data to finish loading.
In this chapter, we are going to learn how to use Hooks to handle forms and form state in React. We have already implemented a form for the CreatePost
component earlier. However, instead of manually handling the form submission, we can use React Form Actions, which not only make it easier to deal with form submission, but also allow us to use Hooks that access the form state. Additionally, we are going to learn about the Optimistic Hook to implement optimistic updates, that is, showing the preliminary result on the client-side before the server-side finishes processing.
The following topics will be covered in this chapter:
- Handling form submission with the Action State Hook
- Simulating blocking UI
- Avoiding blocking UI with the Transition Hook
- Using the Optimistic...