JSX Syntax
What is JSX primarily used for in React?
- Defining component logic
- Describing the user interface
- Managing application state
- Handling events
Component Type
Which type of React component uses the 'this' keyword to access props and state?
- Functional components
- Class components
- Arrow functions
- Stateless Components
Props Definition
How do you pass data from a parent component to a child component in React?
- Using state
- Using props
- Using context
- Using refs
useState Hook Usage
What does the useState hook return?
- Only the state variable
- Only the function to update the state
- A pair containing the state variable and a function to update it
- Nothing
useEffect Dependency Array
What is the purpose of the dependency array in the useEffect hook?
- To specify the initial state
- To control when the effect runs
- To define the cleanup function
- To declare global variables
Event Handling
How do you prevent the default behavior of an event in React?
- Using event.stopDefault()
- Using event.preventDefault()
- Using event.stopPropogation()
- Using event.stopImmediatePropagation()
Conditional Rendering
Which operator is commonly used for inline conditional rendering in JSX?
- For loop
- If statement
- Ternary operator
- Switch statement
Lists and Keys
What is the purpose of the 'key' prop when rendering lists of components in React?
- To style the list items
- To uniquely identify each list item
- To sort the list items
- To hide the list items
Component Lifecycle Methods
Which lifecycle method is called after a component's output has been rendered to the DOM?
- componentWillMount
- componentDidMount
- componentWillUpdate
- componentDidUpdate
Lifting State Up
What does 'lifting state up' mean in React?
- Moving state to a child component
- Moving state to a parent component
- Removing state from the application
- Duplicating the state across components
React Router Basics
Which React Router component is used to navigate between different routes?
- u003CSwitchu003E
- u003CRouteu003E
- u003CLinku003E
- u003CRedirectu003E
Controlled vs Uncontrolled
In React, what is a controlled component?
- A component that doesn't use state
- A component whose value is controlled by React state
- A component that only renders static content
- A component without any event handlers
useContext Hook
What is the primary purpose of the useContext hook?
- To manage local component state
- To access context values within functional components
- To create reusable logic
- To optimize rendering performance
useRef Hook
What can the useRef hook be used for?
- To manage component state
- To persist values between renders without causing re-renders
- To access context values
- To define event handlers
React Performance Optimizations
Which technique can be used to prevent unnecessary re-renders of components?
- ForceUpdate()
- Using shouldComponentUpdate or React.memo
- Using componentWillMount
- Using componentDidUpdate
Virtual DOM
What is the primary function of the Virtual DOM in React?
- To directly manipulate the real DOM
- To provide a lightweight copy of the real DOM for efficient updates
- To replace the real DOM entirely
- To store application state
Code Splitting
What is the purpose of code splitting in React?
- To reduce the size of individual components
- To divide the application into smaller bundles for faster initial load times
- To improve code readability
- To simplify component composition
Error Boundaries
What is the purpose of error boundaries in React?
- To prevent JavaScript errors from occurring
- To gracefully handle errors and prevent the entire application from crashing
- To debug code more efficiently
- To automatically fix errors in the code
Custom Hooks
What is a custom hook in React?
- A pre-built React component
- A JavaScript function that starts with 'use' and can call other hooks
- A special type of event handler
- A method for managing global state
Lazy Loading
What is lazy loading and how does it benefit React applications?
- A technique to load all components at once for faster rendering.
- A technique to defer loading of non-critical resources at page load time, improving initial load time.
- A technique that is only useful for class components.
- A technique to load all images before the rest of the components.