React 1 Flashcards
What is React?
React is a JavaScript library for building user interfaces, developed by Facebook. It allows developers to create reusable UI components and efficiently update the UI in response to changes in application state.
Explain the key features of React.
Key features of React include:
Virtual DOM for efficient DOM manipulation
Component-based architecture for building reusable UI elements
Declarative syntax using JSX
One-way data flow through props
Lifecycle methods for managing component behavior
What are the differences between React and other JavaScript frameworks like Angular or Vue.js?
React uses a virtual DOM, while Angular and Vue.js use a real DOM.
React emphasizes component-based architecture, while Angular uses a MVC pattern and Vue.js uses a MVVM pattern.
React uses JSX for templating, while Angular uses HTML templates and Vue.js supports both templates and JSX.
React’s state management can be handled using libraries like Redux, whereas Angular has built-in tools for state management.
What is JSX in React?
JSX (JavaScript XML) is a syntax extension for JavaScript that allows developers to write HTML-like code within JavaScript. It makes React component code more readable and expressive.
How does React handle components?
React components are reusable, self-contained units of UI that can be composed together to build complex UIs. Components can be either class components or functional components.`
What is a virtual DOM in React?
The virtual DOM is a lightweight, in-memory representation of the actual DOM. React uses the virtual DOM to perform efficient updates to the UI by calculating the difference between the virtual DOM and the actual DOM and only applying the necessary changes.
Explain the lifecycle methods of a React component.
React component lifecycle methods allow developers to hook into various stages of a component’s life, such as initialization, updating, and unmounting. Some commonly used lifecycle methods include componentDidMount, componentDidUpdate, and componentWillUnmount.
What are hooks in React? How do they differ from class components?
Hooks are functions that allow functional components to use state and other React features without writing a class. They enable developers to reuse stateful logic across components, making code more modular and readable compared to class components.
What are controlled and uncontrolled components in React?
Controlled components are React components where form data is controlled by React state. Uncontrolled components are components where form data is handled by the DOM itself.
Explain the concept of state in React.
State in React is an object that represents the current state of a component. It can be modified using the setState method, and changes to state trigger re-renders of the component
What is the significance of keys in React lists?
Keys are used in React lists to uniquely identify elements and optimize rendering performance by helping React identify which items have changed, been added, or been removed.
How do you pass data between components in React?
Data can be passed between components in React using props for parent-to-child communication and callback functions or context for more complex scenarios or child-to-parent communication.
What is the purpose of refs in React?
Refs in React provide a way to access and interact with DOM elements or React components directly. They are commonly used to focus input fields, trigger imperative animations, or integrate with third-party libraries.
How do you handle events in React?
Events in React are handled similarly to regular DOM events, using camelCase event names and passing event handlers as props to components. Event handlers are defined as methods on the component class or as arrow functions in functional components.
Explain the difference between props and state.
Props are read-only data passed from parent to child components, while state is mutable data managed internally by a component. Props are used for passing data down the component tree, while state is used for managing component-specific data and triggering re-renders.
What is Redux and how does it relate to React?
Redux is a predictable state container for JavaScript applications, commonly used with React for managing application state. It provides a centralized store and a set of rules for predictable state updates.