Build a Quiz Component with React
What you'll learn
In this project you’ll follow along with our instructions and build a simple quiz component with React 16.x. You’ll create several components across different files, pass data as props, and propagate events up and down a chain of components.
Table of contents
- Set up your local environment for projects. We'll walk you through everything you need to know, including how to install and configure your environment to be able to complete all of the tasks.
- Create a Quiz component to display quiz information from state that contains data from a local JSON file.
- Refactor the Quiz component to display quiz question data in a new component named QuizQuestion.
- Refactor the QuizQuestion component to display quiz answer buttons in a new component named QuizQuestionButton.
- Create a QuizEnd component that will display a reset quiz link after the quiz is completed.
- Refactor the QuizQuestion component to iterate over an array of questions and display multiple QuizQuestionButtons. Then, create methods and event handlers that call them when the button tag in a QuizQuestionButton component is clicked and have those methods increment the position value in the Quiz component's state.
- Add state to the QuizQuestion class that tracks if a questions was answered incorrectly, and display an error message if the last answer was incorrect.
- Add methods and event handlers that call them when the anchor tag in the QuizEnd component is clicked, and have those methods reset the position value in the Quiz component's state.