Learn React Js MCQs
Prepare React Js MCQs (Multiple choice Questions) for exam and job interviews.
How do you handle form submissions in React?
1) Using `context` API
2) Using controlled components and `onSubmit` event handler
3) Using `onClick` event handler
4) Using `setState`
Answer : Option 2
What is a controlled component in React?
1) A component where form data is handled by React state
2) A component with a ref
3) A component that cannot be modified
4) A component where form data is handled by the DOM
Answer : Option 1
How do you lift state up in React?
1) By using `this.state`
2) By creating a new context
3) By using refs
4) By passing the state to a parent component and managing it there
Answer : Option 4
What does the `useEffect` hook return?
1) The updated state
2) A boolean value
3) An optional cleanup function
4) An array of dependencies
Answer : Option 3
What is the purpose of the `shouldComponentUpdate` lifecycle method?
1) To fetch data from an API
2) To manage state updates
3) To control whether the component should re-render
4) To handle side effects
Answer : Option 3
How do you fetch data in a React component?
1) Using `useEffect` with an async function
2) Using `componentWillMount`
3) Using `useState` hook
4) Using `context` API
Answer : Option 1
What does `ReactDOM.render` do?
1) Renders a React element into the DOM
2) Updates the virtual DOM
3) Handles routing in React
4) Creates a React component
Answer : Option 1
How do you create a class component in React?
1) By using the `useEffect` hook
2) By using the `useState` hook
3) By creating a function
4) By extending `React.Component`
Answer : Option 4
What is JSX in React?
1) A syntax extension that looks similar to HTML
2) A new type of JavaScript
3) A function in React
4) A method for state management
Answer : Option 1
How do you handle events in React?
1) Using the `addEventListener` method
2) Using event handlers in JSX
3) Using `window.addEventListener`
4) Using `document.getElementById`
Answer : Option 2