React 1 Flashcards
(40 cards)
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.
What are the advantages of using Redux with React?
Advantages of using Redux with React include centralized state management, improved predictability and traceability of state changes, easy integration with middleware and dev tools, and support for server-side rendering.
Explain the Flux architecture.
Flux is an architectural pattern for building client-side web applications, introduced by Facebook alongside React. It emphasizes unidirectional data flow, with actions triggering updates to the application state via a central dispatcher.
What is context in React? How is it used?
Context in React provides a way to pass data through the component tree without having to pass props down manually at every level. It is commonly used for sharing global data, such as theme preferences or authentication status, across components.
What is the significance of the setState() method in React?
The setState() method is used in React to update a component’s state and trigger a re-render. It accepts an object containing updated state values or a function that returns such an object.
How can you optimize performance in React applications?
Performance in React applications can be optimized by minimizing unnecessary re-renders, using shouldComponentUpdate or React.memo for memoization, implementing lazy loading and code splitting, and optimizing network requests and data fetching.
What are React Fragments?
React Fragments are a feature that allows developers to group multiple React elements without adding extra nodes to the DOM. They are useful for returning multiple elements from a component’s render method without needing to create a wrapper element.
How do you perform server-side rendering in React?
Server-side rendering in React can be achieved using libraries like Next.js or Gatsby, which generate static HTML on the server and send it to the client. This improves performance and enables better SEO and initial page load times.
What is the significance of the shouldComponentUpdate() method?
The shouldComponentUpdate() method is used in React to optimize rendering performance by allowing components to prevent unnecessary re-renders. It returns a boolean value indicating whether the component should re-render based on changes to props or state.