wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

React Quiz

Total questions: 18

Worksheet time: 23mins

Name
Class
Date
1.

What is JSX in React?

a)

A JavaScript library

b)

A syntax extension for JavaScript

c)

A CSS framework

d)

A database language

2.

Which hook is used to manage state in a functional component?

a)

useEffect

b)

useRef

c)

useState

d)

useContext

3.

Props in React are:

a)

Mutable

b)

Immutable

c)

Stored in state

d)

Used only in class components

4.

What does useEffect run by default?

a)

Only once

b)

On every render

c)

Only on state change

d)

Only on props change

5.

Which method is used to render a list in React?

a)

for

b)

forEach

c)

map

d)

reduce

6.

What is the correct key rule in list rendering?

a)

Keys should be random

b)

Keys should be index always

c)

Keys should be unique

d)

Keys are optional

7.

Which hook is used to share data globally?

a)

useState

b)

useEffect

c)

useContext

d)

useRef

8.

Controlled components store input values in:

a)

DOM

b)

LocalStorage

c)

React state

d)

Props

9.

Which is NOT a valid way to conditionally render in React?

a)

Ternary operator

b)

&& operator

c)

if inside JSX

d)

Logical operators

10.

Why is key important in React lists?

a)

Styling

b)

Faster API calls

c)

Efficient re-rendering

d)

Form validation

11.

What is the difference between props and state?

a)

Props are read-only and passed from parents; state is mutable and managed within the component

b)

Props are mutable and internal; state is external to the component

c)

Both props and state are immutable and serve the same purpose

d)

State is passed from parents; props are managed internally

12.

Explain controlled vs uncontrolled components.

a)

Controlled components manage input values through React state; uncontrolled components rely on native DOM inputs accessed via refs

b)

Controlled components store values in LocalStorage; uncontrolled components sync with Redux

c)

Controlled components are class-based; uncontrolled components are functional

d)

Controlled components use useEffect; uncontrolled components use useContext

13.

When should you use useEffect with an empty dependency array?

a)

When you need the effect to run only once after the component mounts

b)

When you need the effect to run on every render

c)

When the effect should run only when props change

d)

When the effect should run only on state updates

14.

In a React functional component that displays a list of products, which array method should you use to return JSX for each product?

a)

map

b)

reduce

c)

forEach

d)

filter

15.

For a simple React form using useState with one input field and a submit handler, which pattern correctly manages the input and submission?

a)

Use onChange to update state for the input value and onSubmit to prevent default and process the state

b)

Use useEffect to manage the input and submit without state

c)

Use an uncontrolled input with refs and no submit handler

d)

Store the input directly in LocalStorage on each keystroke and rely on default browser submission

16.

What is map() function in javascript and explain what it actually does ?
( explanation with example is required)

4 lines
17.

Write the syntax of useState Hook ?

4 lines
18.

Write a function enclosed in a setTimeout function which will run an api ( https://dummyjson.com/posts ) to fetch only the posts over views > 300 .

4 lines