Learn React Js MCQs

Prepare React Js MCQs (Multiple choice Questions) for exam and job interviews.

How do you update state based on the previous state?

1) By passing a function to `setState`

2) By directly modifying the state

3) By using `useEffect`

4) By using props

Answer : Option 1

What is the purpose of `componentDidMount` lifecycle method?

1) To run code after the component mounts

2) To run code before the component unmounts

3) To run code when the component updates

4) To set initial state

Answer : Option 1

How do you create a higher-order component?

1) By creating a function that takes a component and returns a new component

2) By using `useEffect`

3) By using `props`

4) By using `context`

Answer : Option 1

What does `useCallback` do?

1) Memoizes a callback function

2) Manages state

3) Creates a ref

4) Handles side effects

Answer : Option 1

What is the purpose of `getDerivedStateFromProps`?

1) To update state based on props changes

2) To render the component

3) To handle side effects

4) To create refs

Answer : Option 1

How do you access context in a functional component?

1) Using `useContext`

2) By using `props`

3) By using `state`

4) By using `refs`

Answer : Option 1

What is the purpose of `shouldComponentUpdate`?

1) To determine if a component should re-render

2) To manage state

3) To create refs

4) To handle side effects

Answer : Option 1

How do you trigger a re-render manually?

1) By updating the state

2) By using `useEffect`

3) By using `useMemo`

4) By using `useRef`

Answer : Option 1

What does `useMemo` do?

1) Memoizes a value to optimize performance

2) Creates a ref

3) Handles side effects

4) Manages state

Answer : Option 1

How do you create dynamic styles in React?

1) By using inline styles or styled-components

2) By using static CSS

3) By using global styles

4) By using context

Answer : Option 1