Learn React Js MCQs
Prepare React Js MCQs (Multiple choice Questions) for exam and job interviews.
How do you handle default props in a functional component?
1) Using the `defaultProps` static property
2) Using the `prop-types` library
3) Using default function parameters
4) Using `useState`
Answer : Option 3
What is the purpose of the `useTransition` hook in React?
1) To handle side effects
2) To manage state
3) To manage asynchronous state transitions
4) To optimize performance
Answer : Option 3
How do you unmount a component?
1) Using `componentDidUnmount`
2) Using `componentWillUnmount`
3) Using `useEffect`
4) Using `useLayoutEffect`
Answer : Option 2
What is the purpose of the `React.PureComponent` class?
1) To handle side effects
2) To optimize rendering by implementing a shallow prop and state comparison
3) To manage state
4) To create refs
Answer : Option 2
How do you handle forms in React?
1) Using `document.querySelector`
2) Using uncontrolled components
3) Using controlled components
4) Using `useEffect`
Answer : Option 3
What is the purpose of the `React.Fragment` component?
1) To group multiple elements without adding extra nodes to the DOM
2) To handle side effects
3) To manage state
4) To create a ref
Answer : Option 1
How do you update state in a functional component?
1) Using `useState`
2) Using `this.setState`
3) Using `useReducer`
4) Using `useEffect`
Answer : Option 1
What is the purpose of the `shouldComponentUpdate` lifecycle method?
1) To handle side effects
2) To manage state
3) To prevent unnecessary re-renders
4) To update the component
Answer : Option 3
How do you create a context provider?
1) Using `React.createContext.Provider`
2) Using `useState`
3) Using `useEffect`
4) Using `React.createRef`
Answer : Option 1
What does the `useId` hook do in React?
1) Manages state
2) Handles side effects
3) Generates a unique ID that is stable across renders
4) Creates refs
Answer : Option 3