Sometimes when we create a form, there could be a lot of information that we want. If you put all of the fields on one page, probably it could annoy the user and he might leave before finishing the form. If you want to improve the user experience, you can do a multi-step form.
In this article, I will write about how to do a multi-step form in React. It is a sign-up form. In the first step, I will collect the user’s organization information; and then on the second step, I will collect the user’s personal information. And once it is all done, it will show you a success(or failed) message.
The very intuitive way to solve this problem will be to create three different components to fulfill what I want to do in three steps. That’s true! However, think about that, do I need three IRRELEVANT components? NO!
All these three components are part of my sign-up process and they will share somethings in common. For example, on the second step, it is going to submit the information it gets from BOTH the second and the first component. After submitted, the third component will show you a hint according to if you submit successfully or not.
How do you share all of this information among three different components? The answer is: use a container component!
With a parent component on the top, we can have these advantages:
#state-management #programming #javascript #forms #react