wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

React Interview

Total questions: 93

Worksheet time: 47mins

Name
Class
Date
1.

What is React?

a)

A library for handling HTTP requests

b)

A library for building user interfaces

c)

A database management system

d)

A CSS preprocessor

2.

What are components in React?

a)

Reusable UI elements

b)

The logic part of React

c)

Database structures

d)

React's core library code

3.

What is JSX?

a)

JavaScript extension

b)

HTML preprocessor

c)

XML-like syntax to write React components

d)

JavaScript compiler

4.

What is the difference between functional and class components?

a)

Functional components are stateful

b)

Functional components are stateless

c)

Class components are only for styling

d)

Class components can't manage state

5.

How do you pass data to components in React?

a)

Through props

b)

Through events

c)

Through context

d)

Directly by DOM manipulation

6.

What is the correct syntax for using a prop in a functional component?

a)

this.props.name

b)

props.name

c)

{props}.name

d)

props().name

7.

What is the use of `useState` in React?

a)

To manage component lifecycle

b)

To manage component state in functional components

c)

To bind event handlers

d)

To handle API requests

8.

Which hook is used for side effects in React?

a)

useState

b)

useEffect

c)

useContext

d)

useReducer

9.

What does `useEffect` do?

a)

Handles event listeners

b)

Fetches data and runs side effects

c)

Manages state

d)

Handles component updates

10.

How are state updates managed in functional components?

a)

this.setState

b)

useState()

c)

setEffect()

d)

setReducer()

11.

What is the purpose of `useContext` in React?

a)

To manage state globally

b)

To share data across components without props

c)

To render components conditionally

d)

To handle form inputs

12.

What is React’s Virtual DOM?

a)

The real DOM used in browsers

b)

A copy of the actual DOM for performance optimization

c)

A framework for data storage

d)

A database engine

13.

How does React differ from other UI libraries?

a)

It focuses on state management only

b)

It uses a Virtual DOM for faster updates

c)

It directly manipulates the DOM

d)

It’s only used for mobile apps

14.

What does React.memo() do?

a)

Memoizes expensive calculations

b)

Optimizes functional components by memoizing them

c)

Stores variables in memory

d)

Handles asynchronous tasks

15.

How do you conditionally render a component in React?

a)

Using if-else

b)

Using try-catch

c)

Using ternary operators or short-circuit evaluation

d)

Using switch-case

16.

What is the role of `key` in lists in React?

a)

To track elements in the DOM efficiently

b)

To manage state

c)

To manage CSS classes

d)

To set element attributes

17.

What happens when you change the state in React?

a)

The component rerenders

b)

The state is reset

c)

The DOM updates instantly

d)

The component is destroyed and recreated

18.

How can you optimize the performance of a large React application?

a)

By adding more components

b)

By using React.memo

c)

By removing all keys from lists

d)

By using class components exclusively

19.

What does `useReducer` do?

a)

Handles API requests

b)

Provides an alternative to `useState` for complex state logic

c)

Optimizes component rendering

d)

Manages form validation

20.

How does React handle forms?

a)

With form context

b)

With controlled or uncontrolled components

c)

By using `useForm` hook

d)

Through context API

21.

What are controlled components?

a)

Components where form data is handled by the DOM

b)

Components where form data is handled by React state

c)

Components that don’t accept props

d)

Components that don’t have state

22.

What is a PureComponent?

a)

A component that ignores prop changes

b)

A component that renders only once

c)

A component that implements `shouldComponentUpdate` for performance

d)

A component without any children

23.

What is the Context API?

a)

A method to optimize re-rendering

b)

An API to manage component styles

c)

An API to pass data deeply without prop drilling

d)

A way to fetch data from an API

24.

What is the difference between `useEffect` and `useLayoutEffect`?

a)

`useEffect` runs before DOM painting

b)

`useLayoutEffect` runs after painting

c)

`useEffect` runs after DOM painting

d)

`useLayoutEffect` runs before rendering

25.

How can you fetch data in React?

a)

Using `fetch` or `axios` inside `useEffect`

b)

Directly in render method

c)

Using `useState`

d)

Using `useReducer` in class components

26.

What is React.StrictMode?

a)

A mode that speeds up the app

b)

A mode that helps identify potential problems

c)

An API for strict typing

d)

An alternative to development mode

27.

What does `React.Fragment` do?

a)

Adds unnecessary divs to the DOM

b)

Groups elements without adding extra nodes to the DOM

c)

Prevents re-renders

d)

Handles API requests

28.

How can you share logic between components?

a)

Using `useState`

b)

Using `useContext`

c)

Using custom hooks

d)

Using `useEffect`

29.

What is reconciliation in React?

a)

The process of updating the actual DOM

b)

The process of combining multiple components

c)

The process of comparing Virtual DOM with actual DOM

d)

The process of making components faster

30.

What is ReactDOM used for?

a)

Managing the Virtual DOM

b)

Rendering components to the real DOM

c)

Handling CSS in React

d)

Managing Redux store

31.

How can you force a re-render in React?

a)

`forceUpdate()`

b)

`setState()` with the same state

c)

By returning null

d)

By directly manipulating the DOM

32.

What is lazy loading in React?

a)

Loading components or data only when needed

b)

Loading data at the beginning of the application

c)

Optimizing performance by caching components

d)

Loading components asynchronously in development

33.

What are React portals?

a)

A way to optimize rendering

b)

A way to render components outside the root DOM node

c)

A way to pass props to children

d)

A way to manage child components

34.

What is the role of `shouldComponentUpdate`?

a)

Determining if a component should re-render

b)

Forcing a component to update

c)

Blocking component updates

d)

Optimizing child components

35.

How can you handle errors in React?

a)

Using try-catch blocks in JSX

b)

Using error boundaries

c)

Using `useState` for errors

d)

By throwing errors directly

36.

What is the use of `forwardRef`?

a)

To manage refs in state

b)

To pass refs to children components

c)

To manage context API

d)

To render components conditionally

37.

How do you manage global state in a large React app?

a)

Using `useState` across all components

b)

Using `useContext` or Redux

c)

By passing props deeply

d)

Using `useReducer` in every component

38.

What is the role of Redux in a React application?

a)

Managing side effects

b)

Managing the component lifecycle

c)

Managing global state in a predictable manner

d)

Handling HTTP requests

39.

How does React Router work?

a)

It refreshes the entire page

b)

It manages dynamic routing without reloading the page

c)

It forces page reloads

d)

It handles WebSocket connections

40.

What is the purpose of `useRef` in React?

a)

To hold mutable values that persist between renders

b)

To trigger re-renders

c)

To manage state

d)

To force component updates

41.

How do you create a context in React?

a)

Using `useState`

b)

Using `createContext()`

c)

Using `useContext()`

d)

Using `useReducer()`

42.

What is the function of `defaultProps`?

a)

To set default values for props

b)

To set default state values

c)

To trigger re-renders

d)

To handle form defaults

43.

How do you lazy load a component in React?

a)

Using `React.memo`

b)

Using `useEffect`

c)

Using `React.lazy` with `Suspense`

d)

Using `useReducer`

44.

What is the significance of prop types in React?

a)

They ensure props are passed correctly at runtime

b)

They allow components to accept any prop

c)

They control component lifecycle

d)

They optimize component rendering

45.

What does `useImperativeHandle` do?

a)

Allows refs to modify child component instances

b)

Forces a component to re-render

c)

Optimizes parent-child communication

d)

Handles context updates

46.

What is the difference between `state` and `props` in React?

a)

State is immutable

b)

Props are mutable

c)

State is managed within the component

d)

Props are managed within the component

47.

How does `useCallback` work?

a)

It memoizes functions to avoid unnecessary re-creations

b)

It memoizes components

c)

It handles side effects

d)

It optimizes DOM manipulation

48.

What is server-side rendering (SSR) in React?

a)

Rendering the UI only on the client side

b)

Rendering the UI on the server for better performance

c)

Rendering only static pages

d)

Rendering components in parallel on the client side

49.

What is the primary use of `useMemo` in React?

a)

To manage component state

b)

To handle side effects

c)

To memoize expensive calculations

d)

To manage context

50.

When should you use `useCallback`?

a)

To memoize functions between renders

b)

To optimize component rendering

c)

To fetch data from an API

d)

To manage global state

51.

How does React's reconciliation algorithm work?

a)

It compares the new tree with the previous one

b)

It directly manipulates the real DOM

c)

It re-renders the entire tree

d)

It removes all components and adds them again

52.

What is the benefit of using `React.lazy()` and `Suspense`?

a)

To handle side effects

b)

To lazy load components for better performance

c)

To optimize state management

d)

To render components based on props

53.

What problem does the `ErrorBoundary` component solve?

a)

It handles CSS in components

b)

It helps in catching JavaScript errors in the component tree

c)

It handles event propagation

d)

It manages state globally

54.

What does `useEffect(() => {...}, [])` signify?

a)

Runs the effect only once after initial render

b)

Runs on every re-render

c)

Runs only when state changes

d)

Runs only on component unmount

55.

What is the difference between `useMemo` and `useCallback`?

a)

`useMemo` memoizes values, `useCallback` memoizes functions

b)

`useMemo` and `useCallback` both memoize values

c)

`useMemo` handles API calls, `useCallback` does not

d)

`useMemo` is for context, `useCallback` is for state

56.

How does `Context.Provider` work in React?

a)

It provides a state management solution

b)

It provides values to components that subscribe to the context

c)

It handles API calls

d)

It deals with CSS class management

57.

Why would you choose `useReducer` over `useState`?

a)

When you need to handle side effects

b)

When your state logic is complex or state depends on previous values

c)

When your application is small

d)

When you need to memoize functions

58.

What is the purpose of `shouldComponentUpdate` in class components?

a)

To determine if a component should re-render

b)

To prevent state updates

c)

To trigger a re-render

d)

To update the parent component

59.

What does the `useRef` hook do in React?

a)

It triggers re-renders

b)

It creates a mutable object to hold a DOM reference or persist values between renders

c)

It manages state

d)

It handles form data

60.

What is the advantage of using `React.PureComponent`?

a)

It prevents components from updating unnecessarily

b)

It forces a re-render of the component

c)

It handles side effects

d)

It optimizes form submissions

61.

When does `useEffect` with no dependencies (`[]`) run?

a)

Only after the initial render

b)

On every render

c)

When the component unmounts

d)

Whenever a state or prop changes

62.

How do you optimize a large React app's performance?

a)

By using `useMemo` and `useCallback`

b)

By adding more components

c)

By switching to class components

d)

By preventing props from being passed down

63.

What are higher-order components (HOCs) in React?

a)

A component that manages forms

b)

A component that passes props to children

c)

A function that takes a component and returns a new component

d)

A lifecycle method in class components

64.

What is `useContext` used for in React?

a)

To handle side effects

b)

To manage state locally

c)

To consume a context value without prop drilling

d)

To memoize components

65.

How does the `React.Children` utility help?

a)

It handles state in children components

b)

It allows us to iterate over and manipulate children components

c)

It prevents component re-renders

d)

It manages child lifecycle events

66.

What is the significance of the `defaultValue` prop in React context?

a)

It provides a fallback value if no Provider is found

b)

It sets the initial state of a component

c)

It triggers a re-render

d)

It handles global state

67.

How does `StrictMode` help in React development?

a)

By improving app performance

b)

By highlighting potential problems and deprecated practices in the code

c)

By handling state optimally

d)

By optimizing the use of context

68.

What does the term "lifting state up" mean in React?

a)

Moving state to a higher-level component to make it shared among child components

b)

Moving state to Redux

c)

Passing state via props

d)

Storing state outside React's tree

69.

How does React handle events differently than plain HTML?

a)

React uses synthetic events that wrap the browser’s native event

b)

React doesn’t support events

c)

React uses native events directly

d)

React only supports custom events

70.

What is the difference between controlled and uncontrolled components in forms?

a)

Controlled components have their form data managed by the DOM

b)

Uncontrolled components use state

c)

Controlled components manage form data through React state

d)

Uncontrolled components manage state on their own

71.

How does `useImperativeHandle` help with refs in React?

a)

It prevents refs from being passed to children

b)

It allows you to customize the ref object passed to a child component

c)

It allows event handling on refs

d)

It manages state in refs

72.

How do you handle API requests in React?

a)

Using `useState`

b)

Using `useEffect` for side effects

c)

Using `useContext`

d)

Using React.memo for API calls

73.

What is server-side rendering (SSR) in React?

a)

Rendering components on the server and sending a fully-rendered page to the client

b)

Rendering components in parallel

c)

Rendering components only on the client

d)

Rendering components asynchronously

74.

What is a higher-order function in JavaScript?

a)

A function that takes another function as an argument

b)

An event handler function

c)

A lifecycle method

d)

A CSS-related function

75.

Why is immutability important in React state?

a)

It allows for shallow comparison, making re-renders more efficient

b)

It prevents memory leaks

c)

It makes state updates faster

d)

It prevents UI rendering issues

76.

How can you prevent a component from re-rendering in React?

a)

Using `React.memo()`

b)

Using `useContext`

c)

Using `useState` to stop updates

d)

Using `forceUpdate()`

77.

What does `React.lazy()` help with?

a)

Optimizing forms

b)

Lazy loading components for better performance

c)

Handling global state

d)

Managing refs

78.

What are React portals?

a)

A way to pass props down to deeply nested components

b)

A way to render children outside the DOM hierarchy of the parent component

c)

A way to handle form submissions

d)

A way to manage component updates

79.

How do you handle error boundaries in React?

a)

By wrapping components with `ErrorBoundary`

b)

By using `useEffect`

c)

By using `useCallback`

d)

By handling state in `useState`

80.

What is the purpose of `PropTypes` in React?

a)

To validate props passed to a component

b)

To set initial state values

c)

To manage events

d)

To force re-renders

81.

What is the React Fiber architecture?

a)

React's way of handling forms

b)

A new algorithm for better managing component rendering

c)

React’s state management library

d)

React’s lifecycle method

82.

Why would you use `React.StrictMode`?

a)

To prevent event handling errors

b)

To highlight potential issues and avoid side effects in code

c)

To optimize class component rendering

d)

To manage API calls

83.

How do you handle multiple state variables in a functional component?

a)

Using multiple `useState` calls

b)

Using a single `useState` with an object

c)

Using `useReducer`

d)

Using `useEffect` for each state

84.

What does `forwardRef` enable in React?

a)

It allows a parent component to pass a ref to its child

b)

It passes state down to children

c)

It manages global context

d)

It memoizes child components

85.

How do you achieve conditional rendering in React?

a)

Using `useEffect`

b)

Using `if` statements

c)

Using ternary expressions or logical `&&` operators

d)

Using context providers

86.

What are fragments used for in React?

a)

To group multiple elements without adding extra nodes to the DOM

b)

To memoize state

c)

To manage global state

d)

To pass props to children

87.

Why should you avoid using index as a key in lists?

a)

It causes performance issues

b)

It creates DOM nodes dynamically

c)

It can cause issues with component identity during re-rendering

d)

It prevents re-renders

88.

How does `useEffect` cleanup function work?

a)

It resets the component state

b)

It runs after the component unmounts or before re-running the effect

c)

It manages global state

d)

It prevents re-rendering of the component

89.

How can you optimize component re-renders in React?

a)

Using `useCallback` and `useMemo`

b)

By passing props deeply

c)

Using class components only

d)

By manually manipulating the DOM

90.

What is React’s `Profiler` used for?

a)

To identify performance bottlenecks in React applications

b)

To handle global state

c)

To optimize forms

d)

To manage refs and state

91.

What is the difference between `getDerivedStateFromProps` and `componentDidMount`?

a)

`getDerivedStateFromProps` updates state before rendering based on props, `componentDidMount` runs after the component mounts

b)

`getDerivedStateFromProps` runs after rendering, `componentDidMount` is only for updates

c)

`getDerivedStateFromProps` manages state globally, `componentDidMount` manages local state

92.

How does React handle memory leaks?

a)

React automatically detects and handles them

b)

By using cleanup functions inside `useEffect`

c)

By triggering a re-render

d)

By using `useState` hooks for memory management

93.

What is the difference between `componentWillUnmount` and `useEffect` cleanup?

a)

`componentWillUnmount` runs only in class components, `useEffect` cleanup runs in functional components

b)

`componentWillUnmount` prevents re-rendering, `useEffect` cleanup resets state

c)

`componentWillUnmount` handles side effects