Create Modern Quiz With React JS?

Learn a modern Quiz app demo here

Step:

  1. Create React App
  2. Learn Folder Str.
  3. Index.js File
  4. Demo Data
  5. Components

Create React App:

First, Create New React Project on your laptop use This command:

npx create-react-app quiz-app 
cd quiz-app
npm start

Learn Folder Str.

In the Src folder

Src folder str

Index.js File

Index.js main file in the file str. we add CSS file and import component file on index.js

index.js file code

Style For Quiz:

All Styles for the body, header, MainDiv as card, And a button. Create on this file

Style CSS

Demo Data:

In the data.js file, I create a variable Name Quizdata. We assign data from of array in the Quizdata variable.

Data.js file

Components

Header:

Header component we return a simple h1 tag for the app title

Header.js

Quiz:

Quiz components work with 5 step

1 step:

Create the state. In-State we create an object. in this object, we create a dataQuestion variable with an array

2 step

We create a function. function name setStateFunstion in this function use react setState method And set data form data.js

3 step

ComponentDidMount simple we call setStateFunstion

4 step

In this step, we use a map() Function. Map () function work with a JavaScript array. In this array map() get data and then we return h2 and Answer component.

Quiz.js

Answer:

Two-step:

use two-step we learn Answer.js

1 step:

Create a state with 3 parameters first Answer, second clickCheck, and third rightAnaswer.

2 step

We use javascript ternary operator, map function, and event function to clickCheck true to get value to return a button. In this button, we call an Event function.

Answer.js

--

--

JavaScript || Reactjs || Nextjs || Python || Rust || Biotechnology || Bioinformatic || Front-end Developer || Author https://officialrajdeepsingh.dev/

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Rajdeep singh

JavaScript || Reactjs || Nextjs || Python || Rust || Biotechnology || Bioinformatic || Front-end Developer || Author https://officialrajdeepsingh.dev/