Background
React is a JavaScript library to build user interfaces. It is used to build single-page applications and allows to create reusable UI components. React JS is also known as React or React.js.
This article is being read specifically for purposes like:
To validate and check your React advanced level knowledge.
To explore and understand the advanced features of React along with their use cases and examples.
To crack or clear advanced level certifications, challenges, or interviews of React.
Questions
Which of the following option is NOT a React Hook?
What is the benefit of useLayoutEffect over useEffect?
What replaces Redirect in React Router v6?
What is the execution of useEffect(() => {}, [])?
What is real use-case for useReducer over useState?
What is use of jest.fn()?
When to use useImperativeHandle?
What is the role of Provider in Context API?
Which of the following testing method checks if a component is rendered?
In which scenario to use React.PureComponent?
How to prevent re-renders of child components in React?
What does the useMemo hook do in React?
How to improve re-render performance of a list component?
Which hook helps to prevent unnecessary re-creations of functions on re-renders?
What does createAsyncThunk do in Redux Toolkit?
Which of the following hook is used for animation frame updates?
Which of the following should an Error Boundary component implement?
What is side effect in React?
What is the main benefit of dynamic imports in React?
When to use useTransition?
Which of the option is NOT allowed inside a custom hook?
Which method helps in pre-fetching routes in React Router v6?
Which method logs errors in error boundaries?
Which feature supports concurrent rendering in React?
What is required for SSR in React?
Answers
1. Which of the following option is NOT a React Hook?
A. useLayoutEffect
B. useEffect
C. useRef
D. useFetch
Correct Answer:
D. useFetch
Explanation:
useFetch is not a React Hook. It is a custom hook. Developers create it to encapsulate data-fetching logic. It does not exist in React’s core API.
Why other options are correct?
useLayoutEffect - It is built-in React Hook similar to useEffect. It is used to run synchronously after all DOM mutations.
useEffect - It is a built-in React Hook. It is used to handle side effects.
useRef - It is a built-in React Hook. It is used to persist mutable values and to access DOM elements.
2. What is the benefit of useLayoutEffect over useEffect?
A. Executes after paint
B. Executes before paint
C. Executes asynchronously
D. Handles APIs
Correct Answer:
B. Executes before paint
Explanation:
useLayoutEffect runs synchronously after DOM mutations and before browser paints screen. It is used to read layout values such as size, position, etc. It makes DOM changes before user sees anything and prevents flickering like visual glitches.
Generally useLayoutEffect is used to measure DOM elements using getBoundingClientRect, to adjust layout immediately, and to prevent UI flicker.
useEffect is used by default while useLayoutEffect is used only when to block painting to adjust layout.
Why other options are incorrect?
Executes after paint - It describes useEffect.
Executes asynchronously - useLayoutEffect is synchronous and useEffect is async.
Handles APIs - It is incorrect.
3. What replaces Redirect in React Router v6?
A. <Navigate />
B. <Switch redirect />
C. <Link replace />
D. useNavigation
Correct Answer:
A. <Navigate />
Explanation:
In React Router v6, old Redirect component of v5 was removed and replaced with <Navigate />.
<Navigate /> is used programmatically to redirect users to another route. It is simplified and modernized.
JSX
import { Navigate } from "react-router-dom";
function ProtectedRoute({ isAuth }) {
return isAuth ? <Dashboard /> : <Navigate to="/login" replace />;
}Here, <Navigate /> replaces Redirect for handling redirects.
Why other options are incorrect?
<Switch redirect /> - Switch is replaced by Routes in v6.
<Link replace /> - It does not perform redirects. It only changes navigation behavior.
useNavigation - It does not perform redirection. It is hook used for navigation state.
4. What is the execution of useEffect(() => {}, [])?
A. Runs on every render
B. Runs on mount only
C. Runs after every user input
D. Never runs
Correct Answer:
B. Runs on mount only
Explanation:
useEffect(() => {}, []) has empty dependency array. Hence, it runs effect once, after component mounted. It does not rerun on re-renders or state/prop changes.
It is generally used to call API on component load, to setup event listener, to initialize or subscribe logic.
JavaScript
useEffect(() => {
// side effect code
}, []);Why other options are incorrect?
Runs on every render - This happen only if no empty array mentioned.
Runs after every user input - This happen only if user input changes dependency.
Never runs - It is incorrect. Because, it runs on mount.
5. What is real use-case for useReducer over useState?
A. Simple boolean toggles
B. Static components
C. Controlled inputs
D. Complex state transitions
Correct Answer:
D. Complex state transitions
Explanation:
useReducer is used for complex state transitions. It is used to manage next state which depends on previous state. It allows to manage multiple related state values. Generally, state updates follow actions such as add, remove, reset item.
It is best option to manage component’s complex state logic, to update state depends on previous state, or to handle multiple action types. useReducer is lightweight alternative to Redux.
JavaScript
const reducer = (state, action) => {
switch (action.type) {
case "increment":
return { count: state.count + 1 };
case "decrement":
return { count: state.count - 1 };
default:
return state;
}
};
const [state, dispatch] = useReducer(reducer, { count: 0 });Why other options are incorrect?
Simple boolean toggles - useState is best option for this.
Static components - It is incorrect. Because, no state management is required for this.
Controlled inputs - useState is used for it.
6. What is use of jest.fn()?
A. Runs all tests
B. Creates a mock function
C. Declares a test
D. Finds components
Correct Answer:
B. Creates a mock function
Explanation:
jest.fn() is a utility provided by Jest. It is used to create mock function. Mock function permits to track how function called i.e. arguments/parameters, return values, count call, etc. It replaces actual implementations in tests.
jest.fn() is used for mocking callbacks/dependencies and to verify interaction in unit tests.
JavaScript
const mockFn = jest.fn();
mockFn(1, 2);
expect(mockFn).toHaveBeenCalled();
expect(mockFn).toHaveBeenCalledWith(1, 2);Why other options are incorrect?
Runs all tests - Jest CLI is used to handles test execution.
Declares a test - test() or it() are used to declare test.
Finds components - Jest doesn’t allow component finding.
7. When to use useImperativeHandle?
A. For DOM manipulation
B. When passing props
C. To customize ref handling
D. For lazy loading
Correct Answer:
C. To customize ref handling
Explanation:
useImperativeHandle is used to customize ref handling. It allows to control methods/values exposed to parent component through ref. It is a React Hook and mostly used with forwardRef to expose specific imperative API. It allows to define custom interface for ref.
useImperativeHandle is used to expose only certain methods such as focus, reset, etc. It allows to hide internal implementation details. Using it parent can imperative control over child component.
JavaScript
import { forwardRef, useImperativeHandle, useRef } from "react";
const Input = forwardRef((props, ref) => {
const inputRef = useRef();
useImperativeHandle(ref, () => ({
focus: () => inputRef.current.focus(),
}));
return <input ref={inputRef} />;
});Here, parent can call ref.current.focus() method without accessing DOM directly.
Why other options are incorrect?
For DOM manipulation - useRef is used for that instead of useImperativeHandle.
When passing props - It is incorrect. Props flow don’t involve refs.
For lazy loading - React.lazy and Suspense are used for that.
8. What is the role of Provider in Context API?
A. Creates global variables
B. Provides values to consumers
C. Consumes context
D. Initializes React
Correct Answer:
B. Provides values to consumers
Explanation:
The role of Provider in Context API is to provide values to consumers. It is used to provide/supply data to all child components which consumes that context. There is no need to pass props manually at every level. It is used to define what data is shared and where it is available in component tree.
JSX
const ThemeContext = React.createContext();
function App() {
return (
<ThemeContext.Provider value="dark">
<Toolbar />
</ThemeContext.Provider>
);
}
function Toolbar() {
const theme = React.useContext(ThemeContext);
return <div>{theme}</div>;
}Here, it outputs dark as <Toolbar/> component can access using useContext(MyContext) or Context.Consumer.
Why other options are incorrect?
Creates global variables - Context is scoped to component tree only instead of global.
Consumes context - useContext or Context.Consumer are used for that.
Initializes React - It is not elated to Context.
9. Which of the following testing method checks if a component is rendered?
A. screen.findBy()
B. expect().toBeVisible()
C. screen.getByText()
D. waitFor()
Correct Answer:
C. screen.getByText()
Explanation:
screen.getByText() testing method is used to check whether component, part of it, or specific text within it is rendered in DOM or not.
It synchronously queries DOM and throws error if text not found. It is used to confirm the rendering.
JavaScript
render(<MyComponent />);
expect(screen.getByText("Hello World")).toBeInTheDocument();Here, If text is not present then getByText throws error and causing test to fail.
Why other options are incorrect?
screen.findBy() - It is used for async rendering and waits for elements to appear. It is used when elements appear and after async actions such as API calls, timers, etc.
expect().toBeVisible() - It is incorrect as it requires element first.
waitFor() - It is used to wait for async changes instead of direct rendering checking. It is used to wait for async updates.
10. In which scenario to use React.PureComponent?
A. Class components with props comparison
B. Functional hooks
C. Context providers
D. Testing environments
Correct Answer:
A. Class components with props comparison
Explanation:
React.PureComponent is used with class based components to optimize rendering performance. It allows to implement shallow comparison of props and states to optimize performance. It automatically implements shouldComponentUpdate with shallow comparison to avoid unnecessary renders.
Based on shallow comparison, component will no re-render if props or state not changed. It helps to avoid unnecessary re-rendering while component receives same data repeatedly.
JavaScript
class MyComponent extends React.PureComponent {
render() {
return <div>{this.props.value}</div>;
}
}Here, MyComponent only re-render if value changes.
JavaScript - Modern equivalent - For functional components, use:
const MyComponent = React.memo(function MyComponent(props) {
return <div>{props.value}</div>;
});Why other options are incorrect?
Functional hooks - PureComponent is only for class components. React.memo is used with functional components.
Context providers - It is incorrect. Context uses Provider or Consumer.
Testing environments - It is incorrect. Rendering optimization has no relation with testing.
11. How to prevent re-renders of child components in React?
A. Avoid passing props
B. Use Redux
C. Use React.memo
D. Use class components
Correct Answer:
C. Use React.memo
Explanation:
React.memo is recommended solution for functional components to optimize rendering performance. It is used to prevent unnecessary re-renders if child components through component memoizing.
React.memo memoizes component and then re-renders it only if it’s props change using shallow comparison. If parent re-renders but child will not re-render, if child props are same.
Functional component uses React.memo and class component uses React.PureComponent to optimize child components and avoid unnecessary re-renders while props remain unchanged.
JSX
const Child = React.memo(({ value }) => {
console.log("Child rendered");
return <div>{value}</div>;
});
function Parent() {
const [count, setCount] = React.useState(0);
return (
<>
<Child value="Hello" />
<button onClick={() => setCount(count + 1)}>+</button>
</>
);
}Here, clicking button will not re-render Child, because Child props is not change.
Why other options are incorrect?
Avoid passing props - It is incorrect. Generally, child component needs data.
Use Redux - It is used for state management and it does not automatically prevent re-renders.
Use class components - It is incorrect. Class components uses PureComponent to optimized unnecessary re-renders.
12. What does the useMemo hook do in React?
A. Returns a memoized value
B. Memoizes a component
C. Caches a function
D. Causes re-render
Correct Answer:
A. Returns a memoized value
Explanation:
In React, useMemo hook is used to memoize (cache) computation result and it is recomputed only when it’s dependency changes. It returns memoized value.
It is used for expensive calculation and value is derived from props or state. It allows to avoid unnecessary recalculations on re-renders.
JSX
const expensiveValue = useMemo(() => {
return computeExpensiveValue(a, b);
}, [a, b]);
``Here, computed result is cached and reuses previously computed value unless a or b not changes. It optimize performance by avoiding unnecessary recalculation during re-render.
Why other options are incorrect?

ChiracjacquesPosted Sep 4, 2026, 9:21 AM
Usefull information, Thanks a lot