Learn React Js MCQs
Prepare React Js MCQs (Multiple choice Questions) for exam and job interviews.
What does the `useEffect` hook do by default?
1) Runs the effect after every render
2) Runs the effect only once
3) Runs the effect before the component unmounts
4) Runs the effect before the component mounts
Answer : Option 1
How do you create a new React project?
1) Using `react init`
2) Using `react new`
3) Using `npm start`
4) Using `create-react-app`
Answer : Option 4
What does the `useState` hook return?
1) An array with the state and a function to update it
2) An object with the state and a setState function
3) A function to handle side effects
4) A boolean and an updater function
Answer : Option 1
What is the virtual DOM in React?
1) A tree structure of React components
2) The HTML structure of the app
3) A shadow DOM in the browser
4) A lightweight copy of the actual DOM
Answer : Option 4
What is the purpose of the `React.StrictMode` component?
1) To manage component state
2) To handle routing
3) To identify potential problems in the app
4) To optimize performance
Answer : Option 3
How do you update state in a functional component?
1) Using `this.setState`
2) Using the `useEffect` hook
3) Using `this.state`
4) Using the `setState` function provided by `useState`
Answer : Option 4
What does the `useMemo` hook do?
1) Handles side effects
2) Creates a new context
3) Memoizes a value to prevent unnecessary calculations
4) Manages component state
Answer : Option 3
How do you handle side effects in a class component?
1) Using `shouldComponentUpdate`
2) Using `useEffect` hook
3) Using `componentDidMount` and `componentDidUpdate`
4) Using `componentWillMount`
Answer : Option 3
How do you create a ref in a functional component?
1) Using the `useRef` hook
2) Using `createRef` method
3) Using `this.ref`
4) Using the `useState` hook
Answer : Option 1
What is the purpose of the `render` method in a class component?
1) To update the component state
2) To return the JSX that should be rendered
3) To handle side effects
4) To manage props
Answer : Option 2