Learn React Js MCQs

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

What is the purpose of the `useLayoutEffect` hook?

1) To perform side effects synchronously after all DOM mutations

2) To manage state

3) To handle side effects

4) To create refs

Answer : Option 1

How do you pass props to a child component?

1) By using JSX syntax

2) By using state

3) By using global variables

4) By using refs

Answer : Option 1

What does `React.forwardRef` allow you to do?

1) Pass refs to child components

2) Manage state

3) Handle side effects

4) Create contexts

Answer : Option 1

How do you access the previous state in `useEffect`?

1) By using a ref

2) By using props

3) By using state

4) By using context

Answer : Option 1

What is the difference between `useState` and `useReducer`?

1) useState is for simple state, while useReducer is for complex state logic

2) Both are the same

3) useReducer is for local state, while useState is for global state

4) useState cannot handle arrays

Answer : Option 1

How do you create a responsive layout in React?

1) By using CSS media queries or libraries like styled-components

2) By using fixed widths

3) By using global styles

4) By using refs

Answer : Option 1

What does `useEffect` do when no dependencies are provided?

1) Runs after every render

2) Runs only on mount

3) Runs only on unmount

4) Does not run at all

Answer : Option 1

How do you create a toggle component in React?

1) By using state to toggle a boolean value

2) By using props only

3) By using refs only

4) By using global variables

Answer : Option 1