wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

ReactJS OVerview Unit 11-18

Total questions: 50

Worksheet time: 45mins

Name
Class
Date
1.

Which of the following is true regarding Babel ? (2 correct answers)

a)

A compiler 

b)

A transpiler 

c)

A framework

d)

A programming language

2.

What "_____case" does React DOM use for naming attributes and properties?

a)

Camel (camelCase) 

b)

Pascal (PascalCase) 

c)

Snake (snake_case) 

d)

Kebab (kebab-case) 

3.

What are the smallest building blocks of React apps

a)

Components

b)

Functions

c)

Elements

d)

JSX

4.

A component name must start with ________.

a)

a lowercase letter

b)

a capital letter

c)

a number

d)

everything

5.

Which component lifecycle method runs after the component output has been rendered to the DOM?

a)

componentMounted() 

b)

componentRendered() 

c)

componentDidMount() 

d)

componentDidRender() 

6.

Which component lifecycle method is used to perform the cleanup when the component is removed from the DOM? 

a)

componentUnmounted() 

b)

componentWillUnmount() 

c)

componentDidUnmount() 

d)

None of the above

7.

State of a component is often called ___ data? 

a)

public

b)

protected

c)

private

d)

local or encapsulated 

8.

In order to prevent a component from rendering it should return ___? 

a)

undefined

b)

false

c)

null

d)

empty string

9.

Which of the following activities do we perform while declaring useState in React? 

a)

Object destructuring 

b)

Unpacking object 

c)

Array destructuring 

d)

Unpacking array 

10.

How does React remember which state variable belongs to which useState call?

a)

It makes a lookup table  

b)

It remembers the calling order  

c)

It traverses the calls again, whenever needed  

d)

None of the above 

11.

How many calls can we make to useState or useEffect in a single component? 

a)

Unlimited, but equal calls for both hooks 

b)

Unlimited 

c)

Limited 

d)

Limited, but equal calls for both hooks 

12.

What is passed as an argument in useState() in React? 

a)

Initial value 

b)

State variable 

c)

Function to set state 

d)

All can be passed 

13.

How many possible arguments can useState() take?  

a)

only 1

b)

exactly 2

c)

more than 2

d)

no limit

14.

Which of the following is associated with the execution of useEffect in react?

a)

Synchronous

b)

Asynchronous  

c)

Both are correct

d)

It depends

15.

Return function inside useEffect is call _______

a)

Cleanup function  

b)

Return function  

c)

Final function  

d)

None of the above 

16.

Which of the following could be an application of return function in useEffect? 

a)

To avoid memory leak 

b)

To remove unwanted things 

c)

To reallocate resources 

17.

When should you use the useEffect hook? 

a)

When you need to manage component state 

b)

When you want to trigger a side effect 

c)

When you need to memoize expensive function results 

d)

When you need to optimize rendering performance 

18.

How does the useEffect hook improve performance? 

a)

By reducing the number of component re-renders 

b)

By handling asynchronous operations more efficiently 

c)

By optimizing the component's memory usage 

d)

By providing a clean way to handle side effects 

19.

Can the useEffect hook be used to perform data fetching? 

a)

Yes, it's a recommended approach for data fetching 

b)

No, useEffect is only for managing component state 

c)

Yes, but only once in a project 

d)

Data fetching should be done outside of useEffect 

20.

What happens if you omit the dependency array in the useEffect hook? 

a)

The effect will run once after the initial render 

b)

The effect will run on every render 

c)

The effect will not run at all 

d)

The behavior is undefined 

21.

What is the purpose of returning a cleanup function in useEffect? 

a)

To clean up after the effect has been applied 

b)

To cancel the effect before it's finished 

c)

To prevent memory leaks caused by the effect 

d)

To control the order of effect execution 

22.

Can you use async/await inside the callback function of useEffect? 

a)

Yes, it's a recommended approach 

b)

No, async/await should not be used inside useEffect 

c)

It depends on the scope and scale of the project

d)

Async/await is not supported in useEffect 

23.

How can you provide a default value to a context using the createContext function in React.js? 

a)

By using the defaultValue prop in the Context.Provider 

b)

By passing the default value directly to the useContext hook 

c)

By setting a default value using the useContextDefault method 

d)

By passing a default value to the createContext function 

24.

How can you access the context value outside of the render function in a functional component? 

a)

Using the this.context syntax 

b)

Storing the context value in a global variable 

c)

Creating a separate custom hook 

d)

Context values can only be accessed within the render function 

25.

In the useContext hook, what should be passed as an argument to identify the context to be consumed? 

a)

Context value 

b)

Context type 

c)

Context name 

d)

Context object 

26.

How can you update the context value dynamically using the useContext hook? 

a)

Use the updateContext method 

b)

Context values are immutable and cannot be updated 

c)

Use the setContext method 

d)

By updating the value provided by the context provider 

27.

When should you use the useRef hook?

a)

When you need to manage component state 

b)

When you want to trigger a side effect 

c)

When you need to reference a DOM element 

d)

When you need to optimize rendering performance 

28.

What problem does the useRef hook solve? 

a)

Improving component performance 

b)

Managing asynchronous operations 

c)

Preventing memory leaks 

d)

Accessing and managing DOM elements 

29.

When should you avoid using the useRef hook? 

a)

When you need to manage component state 

b)

When you want to trigger a side effect 

c)

When you need to reference a DOM element 

d)

When you need to optimize rendering performance 

30.

What is the main benefit of using useRef for referencing DOM elements? 

a)

It simplifies component logic 

b)

It automatically updates the DOM elements 

c)

It reduces memory consumption 

d)

It allows safe access and manipulation of DOM elements 

31.

What problem does the useCallback hook solve?

a)

Improving component performance 

b)

Managing asynchronous operations 

c)

Avoiding unnecessary re-renders 

d)

Preventing memory leaks 

32.

How does the useMemo hook improve performance?

a)

By reducing the number of component re-renders 

b)

By handling asynchronous operations more efficiently 

c)

By optimizing the component's memory usage 

d)

By simplifying the component's lifecycle methods 

33.

What happens if you omit the dependencies array in the useMemo hook? 

a)

The function will always be memoized 

b)

The function will never be memoized 

c)

The hook will throw an error 

d)

The behavior is undefined 

34.

How do "action" and "action creator" differ in Redux? 

a)

"Action" is an object describing an event, while "action creator" is a function that returns that object. 

b)

"Action" is a function, while "action creator" is an object describing an event. 

c)

"Action" and "action creator" are synonymous terms.

d)

"Action" and "action creator" are unrelated. 

35.

What can Redux Middleware do in the action processing chain? 

a)

Only intervene in sending actions to reducers.

b)

Provide a way to handle asynchronous actions and intercept actions before they reach reducers.

c)

Only handle actions after they have been processed by reducers. 

d)

Directly handle actions before they are sent to the store. 

36.

What should a reducer in Redux always return if no state changes are made? 

a)

undefined

b)

null

c)

The current state

d)

{} (empty object)

37.

How can you combine multiple reducers into a single reducer in Redux? 

a)

Using combineReducers from the Redux library.

b)

Manually creating a combined reducer without a library. 

c)

Using the reduce method on an array of reducers.

d)

Redux does not support combining multiple reducers.

38.

How do you handle asynchronous actions in Redux?

a)

By using middleware like redux-thunk or redux-saga.

b)

By using synchronous action creators with dispatch.

c)

By writing asynchronous logic directly inside reducers.

d)

Redux does not support asynchronous actions.

39.

In the context of Redux, what are "selectors" and how do they enhance performance? 

a)

Selectors are functions that compute derived data from the Redux store, and they enhance performance by memoizing the results to avoid recalculating on every render. 

b)

Selectors are middleware functions that intercept and modify actions before they reach reducers. 

c)

Selectors are methods of the Redux store that directly update the state based on specific conditions. 

d)

Selectors are used to dispatch actions based on the current state of the store. 

40.

What will the code do?

a)

It will create two props, increment and decrement, that dispatch the corresponding actions.

b)

It will create two props, increment and decrement, that update state directly.

c)

It will create a single prop that dispatches both actions.

d)

It will create two props, but they won't work correctly with Redux. 

41.

Given the following reducer, what will the state be after calling the action SET_NAME with the payload { name: 'Alice' }?

a)

{ name: '' } 

b)

{ name: 'Alice' }

c)

{ name: 'Alice', age: undefined }

d)

{ name: 'Alice', name: 'Alice' }

42.

What will the state be after dispatching two actions sequentially in the following setup?

a)

{ value: 2}

b)

{ value: 1 }

c)

{ value: 0 }

d)

{ value: -1 }

43.

Given the following Redux setup, what will be the state after dispatching the ADD_ITEM action?

a)

{ items: [] }

b)

{ items: ['item1'] }

c)

{ items: ['item1', 'item1'] }

d)

{ items: 'item1' }

44.

What will be the final state after dispatching the RESET action in the following Redux setup

a)

{ count: 11 }

b)

{ count: 10 }

c)

{ count: 0 }

d)

{ count: undefined }

45.

Fill in the blank:

"export default counterSlice. (a)   ; "

46.

Fill in the blank:

"middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat( (a)   ) "

47.

What is the result of using useCallback with an empty dependency array?
const memoizedCallback = useCallback(() => { console.log('Callback'); }, []);

a)

The callback will be recreated on every render.

b)

The callback will be recreated only when dependencies change.

c)

The callback will be the same across renders.

d)

The callback will never execute.

48.

What does the createSlice function from Redux Toolkit return?

a)

A reducer function

b)

Action creators and reducers

c)

Middleware

d)

A store

49.

How does useReducer differ from useState?

a)

useReducer is used for complex state logic, while useState is for simple state management.

b)

useReducer manages side effects, while useState handles state.

c)

useReducer requires a class component, while useState does not.

d)

All are correct

50.

What is the main purpose of combineReducers in Redux?

a)

To merge multiple action creators.

b)

To combine multiple reducers into a single reducer function.

c)

To combine multiple stores.

d)

To merge middleware functions.