React Basics:
-
What is React?
- A. A programming language
- B. A JavaScript library for building user interfaces
- C. A CSS preprocessor
- D. A server-side scripting language
Answer: B. A JavaScript library for building user interfaces
-
What does JSX stand for?
- A. JavaScript XML
- B. JavaScript Extension
- C. JSX doesn't stand for anything
- D. Java XML Syntax
Answer: A. JavaScript XML
-
Which method is used to render a React element into a DOM element?
- A.
renderDOM
- B.
mount
- C.
renderElement
- D.
ReactDOM.render
Answer: D.
ReactDOM.render
- A.
-
In React, what is the purpose of
setState
?- A. To set the initial state of a component
- B. To update the state of a component
- C. To get the current state of a component
- D. To remove a component from the state
Answer: B. To update the state of a component
-
What is the Virtual DOM used for in React?
- A. To create a virtual representation of the browser
- B. To store component styles
- C. To improve performance by updating the actual DOM more efficiently
- D. To handle asynchronous events
Answer: C. To improve performance by updating the actual DOM more efficiently
Component Lifecycle:
-
Which lifecycle method is called after a component renders for the first time?
- A.
componentWillMount
- B.
componentDidMount
- C.
componentWillUpdate
- D.
componentDidUpdate
Answer: B.
componentDidMount
- A.
-
In class components, which method is used to update the state based on props changes?
- A.
componentDidMount
- B.
componentDidUpdate
- C.
componentWillReceiveProps
- D.
componentWillUpdate
Answer: C.
componentWillReceiveProps
- A.
Hooks:
-
Which hook is used for side effects in functional components?
- A.
useEffect
- B.
useSideEffect
- C.
useAsyncEffect
- D.
useLifecycle
Answer: A.
useEffect
- A.
-
What is the purpose of the
useState
hook?- A. To define state in class components
- B. To fetch data from an API
- C. To manage state in functional components
- D. To create a global state
Answer: C. To manage state in functional components
Props and State:
-
What is the key difference between state and props in React?
- A. State is used for internal component data, while props are used for communication between components.
- B. State is immutable, while props are mutable.
- C. State is passed down from parent components, while props are defined within a component.
- D. State is used only in class components, while props are used in functional components.
Answer: A. State is used for internal component data, while props are used for communication between components.
-
In React, how can you pass data from a parent component to a child component?
- A. Using the
setState
method - B. Using the
props
attribute - C. Using the
state
attribute - D. Using the
render
method
Answer: B. Using the
props
attribute - A. Using the
React Router:
-
What is React Router used for?
- A. State management in React applications
- B. Handling routing and navigation in React applications
- C. Managing API requests
- D. Styling React components
Answer: B. Handling routing and navigation in React applications
-
Which component is used to define a route in React Router?
- A.
Router
- B.
Switch
- C.
Route
- D.
Link
Answer: C.
Route
- A.
Redux:
-
What is Redux used for in a React application?
- A. Styling React components
- B. Managing global state
- C. Handling routing and navigation
- D. Fetching data from an API
Answer: B. Managing global state
-
What is an action in Redux?
- A. A plain JavaScript object describing a change in state
- B. A function that calculates the next state
- C. A middleware for handling side effects
- D. A component in a Redux application
Answer: A. A plain JavaScript object describing a change in state
Higher-Order Components (HOC):
-
What is a Higher-Order Component (HOC) in React?
- A. A component with a higher number of children
- B. A function that takes a component and returns a new component with enhanced features
- C. A component with a higher level of state
- D. A component that renders other components
Answer: B. A function that takes a component and returns a new component with enhanced features
React Context:
-
What is React Context used for?
- A. Managing global state
- B. Styling React components
- C. Handling routing and navigation
- D. Creating higher-order components
Answer: A. Managing global state
-
How can you consume a React Context in a functional component?
- A. Using the
this.context
property - B. Using the
useContext
hook - C. Using the
Consumer
component - D. Using the
connect
function
Answer: B. Using the
useContext
hook - A. Using the
Portals:
-
What is a React Portal used for?
- A. Handling API requests
- B. Rendering components outside the normal component hierarchy
- C. Managing global state
- D. Animating React components
Answer: B. Rendering components outside the normal component hierarchy
Testing:
-
Which testing library is commonly used for testing React components?
- A. Jest
- B. Mocha
- C. Jasmine
- D. Enzyme
Answer: A. Jest
Comments