Skills Expanded

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

Setup
15m
  • 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.
Creating a Quiz Component
20m
  • Create a Quiz component to display quiz information from state that contains data from a local JSON file.
Creating a QuizQuestion Component
20m
  • Refactor the Quiz component to display quiz question data in a new component named QuizQuestion.
Creating a QuizQuestionButton Component
20m
  • Refactor the QuizQuestion component to display quiz answer buttons in a new component named QuizQuestionButton.
Creating a QuizEnd Component
15m
  • Create a QuizEnd component that will display a reset quiz link after the quiz is completed.
Displaying Quiz Questions and Handling Events
30m
  • 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.
Displaying An Error Message Based on State
15m
  • 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.
Resetting the Quiz
15m
  • 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.

About the author

Jon is an author, developer, and Pluralsight team member via Code School. Lately, he's been working on content and products that help authors create content efficiently. Prior to that, he worked for several years on interactive learning at Code School, and later helped bring that to Pluralsight as Interactive Content.

Ready to upskill? Get started