Learn React Js MCQs
Prepare React Js MCQs (Multiple choice Questions) for exam and job interviews.
How do you handle side effects in React?
1) Using `useState`
2) Using `useEffect`
3) Using `useReducer`
4) Using `useRef`
Answer : Option 2
What is the purpose of `React.forwardRef`?
1) To handle side effects
2) To pass refs to a child component
3) To create a new context
4) To manage state
Answer : Option 2
How do you create a ref in a functional component?
1) Using `useRef`
2) Using `createRef`
3) Using `useState`
4) Using `useEffect`
Answer : Option 1
What is the purpose of `useState` in React?
1) To handle side effects
2) To manage state in a functional component
3) To create refs
4) To optimize performance
Answer : Option 2
How do you handle form inputs in React?
1) Using `useRef`
2) Using `useState` and controlled components
3) Using `useEffect`
4) Using `useReducer`
Answer : Option 2
What is the purpose of `useReducer` in React?
1) To manage complex state logic
2) To handle side effects
3) To create refs
4) To optimize performance
Answer : Option 1
How do you update the state in React?
1) Using `setState` in class components or `useState` in functional components
2) Using `useEffect`
3) Using `useRef`
4) Using `useMemo`
Answer : Option 1
What is the purpose of `useEffect` in React?
1) To handle side effects in a component
2) To manage state
3) To create refs
4) To optimize performance
Answer : Option 1
How do you pass data to a child component?
1) Using `useState`
2) Using `props`
3) Using `context`
4) Using `useRef`
Answer : Option 2
What is the purpose of `React.Context`?
1) To manage state
2) To pass data through the component tree without having to pass props down manually
3) To handle side effects
4) To create refs
Answer : Option 2