wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

React Events, State, useEffect and Routing

Total questions: 19

Worksheet time: 9mins

Name
Class
Date
1.

What is "state" in React?

a)

A built-in method to handle APIs

b)

An object that holds data that may change over time

c)

A function to trigger re-rendering

2.

How do you define state in a functional component using Hooks?

a)

const [state, setState] = React.useContext()

b)

const state = useState()

c)

const [state, setState] = useState()

3.

Which Hook is used to handle state in a functional component?

a)

useState()

b)

useEffect()

c)

useContext()

4.

What happens when setState() is called in a component?

a)

The component is destroyed

b)

The component updates and re-renders

c)

The app reloads

5.

What is the purpose of an event handler in React?

a)

To fetch API data

b)

To manage user interactions

c)

To call back-end functions

6.

Which is the correct way to write an onClick event in JSX?

a)

<button onClick="handleClick()">Click</button>

b)

<button onclick="handleClick()">Click</button>

c)

<button onClick={handleClick}>Click</button>

d)

<button onclick={handleClick()}>Click</button>

7.

What is a common use case for an onChange event in React?

a)

Detecting when a page reloads

b)

Listening to keyboard presses

c)

Submitting a form

d)

Handling form input changes

8.

What is the main purpose of react-router-dom in a React application?

a)

To manage application state

b)

To manage routing and navigation

c)

To handle HTTP requests

9.

Which component is used to define the routing context in react-router-dom v6?

a)

RouterProvider

b)

HashRouter

c)

BrowserRouter

10.

What does the <Route> component do?

a)

Maps a path to a component

b)

Sends a request to an API

c)

Handles form submissions

11.

Which component should wrap your entire app to enable routing?

a)

<Router>

b)

<Switch>

c)

<NavLink>

d)

<BrowserRouter>

12.

How do you create a link in react-router-dom that doesn’t reload the page?

a)

<a href="/home">Home</a>

b)

<Link to="/home">Home</Link>

c)

<navigate to="/home">Home</navigate>

13.

What does the element prop in <Route> do in v6?

a)

Sets the fallback element

b)

Assigns HTML element

c)

Defines the component to render

14.

What is the purpose of the <Outlet /> component in React Router DOM v6?

a)

To render child routes in a layout

b)

To handle form input

c)

To render the current route selected

15.

What is the primary purpose of the useEffect hook in React?

a)

To update state

b)

To perform side effects like data fetching

c)

To Upgrade DOM

16.

What does the second argument of useEffect represent?

a)

The return value of the function

b)

A callback function

c)

An array of dependencies

d)

The component’s props

17.

What happens when the dependency array in useEffect is empty?

a)

The effect runs only once after the first render

b)

The effect runs on unmount

c)

The effect runs every time

d)

The effect never runs

18.

What will happen if you omit the dependency array in useEffect?

a)

It will run on every render

b)

It won’t run at all

c)

It will throw an error

d)

It will run once

19.

What happens when you add an item (like a variable or state) to the dependency array in useEffect?

a)

The effect will run only once

b)

The effect will run every time that item changes

c)

The effect will stop working