Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted about 2 years ago

Responsive Multi-step form using ReactJS, contextAPI, CSS Modules

accessibility, react
Roy Victor Gagarin•150
@seyren10
A solution to the Multi-step form challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


Hi everyone! This is my first advanced challenge solution for a multi-step form. It took me 2 days to finish this project, and it was quite a tough challenge, especially since creating a multi-step form is new to me. I decided to challenge myself and try to complete it. Since I'm relatively new to React and wanted to gain a deep understanding of the library, I chose not to use any external libraries like Redux for state management, Formik or react-hook-form for form validations, or Tailwind for styling. Instead, I used React Context API, a custom hook for form validation, and CSS modules for styling. Although setting up these tools took more time compared to using libraries, I believe it was worth it because I gained a deeper understanding of React itself.

During the challenge, I encountered a problem and found a solution:

Problem: I didn't know how to create a continuous form that retains its data after rendering another component.

My Solution: I eliminated the use of the <form> element and instead used the values of <input> fields, storing them in a context. So when I need to actually submit the form, I will create a hidden <form> element with <input> fields in the summary section, passing the context data to those inputs.

Here's my process:

I planned to make this a multi-page app, but I thought it would be overkill for this project. Instead, I created a component for each step and rendered them accordingly.

For form validations, I created a custom hook called useInput() that provides a way to validate inputs.

To manage the form states, I created a single context called form-step-context with a separated provider FormStepProvider for form data where I can handle all the operations related to form input.

That's basically it. I would appreciate your feedback to help me improve my coding skills. What are the best practices when creating a multi-step form? Is it okay to put all the states in a single context? I look forward to your responses. Thank you, and happy coding! :)

Code
Loading...

Please log in to post a comment

Log in with GitHub

Community feedback

No feedback yet. Be the first to give feedback on Roy Victor Gagarin's solution.

Join our Discord community

Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!

Join our Discord
Frontend Mentor logo

Stay up to datewith new challenges, featured solutions, selected articles, and our latest news

Frontend Mentor

  • Unlock Pro
  • Contact us
  • FAQs
  • Become a partner

Explore

  • Learning paths
  • Challenges
  • Solutions
  • Articles

Community

  • Discord
  • Guidelines

For companies

  • Hire developers
  • Train developers
© Frontend Mentor 2019 - 2025
  • Terms
  • Cookie Policy
  • Privacy Policy
  • License

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

Oops! 😬

You need to be logged in before you can do that.

Log in with GitHub

How does the accessibility report work?

When a solution is submitted, we use axe-core to run an automated audit of your code.

This picks out common accessibility issues like not using semantic HTML and not having proper heading hierarchies, among others.

This automated audit is fairly surface level, so we encourage to you review the project and code in more detail with accessibility best practices in mind.

How does the CSS report work?

When a solution is submitted, we use stylelint to run an automated check on the CSS code.

We've added some of our own linting rules based on recommended best practices. These rules are prefixed with frontend-mentor/ which you'll see at the top of each issue in the report.

The report will audit all CSS, SCSS and Less files in your repository.

How does the HTML validation report work?

When a solution is submitted, we use html-validate to run an automated check on the HTML code.

The report picks out common HTML issues such as not using headings within section elements and incorrect nesting of elements, among others.

Note that the report can pick up “invalid” attributes, which some frameworks automatically add to the HTML. These attributes are crucial for how the frameworks function, although they’re technically not valid HTML. As such, some projects can show up with many HTML validation errors, which are benign and are a necessary part of the framework.

How does the JavaScript validation report work?

When a solution is submitted, we use eslint to run an automated check on the JavaScript code.

The report picks out common JavaScript issues such as not using semicolons and using var instead of let or const, among others.

The report will audit all JS and JSX files in your repository. We currently do not support Typescript or other frontend frameworks.