React.js Flashcards
What is React?
React is a JavaScript library for building user interfaces
What are the key features of React?
Key features include component-based architecture
Explain the difference between functional and class components
Functional components are JavaScript functions that return React elements. Class components are ES6 classes that extend React.Component and have a render method. Functional components with hooks are now preferred over class components.
What are React Hooks?
https://www.youtube.com/watch?v=TNhaISOUy6Q
Hooks are functions that let you use state and other React features in functional components without writing a class. Examples include useState
What is the useState Hook?
useState is a Hook that lets you add state to functional components. It returns an array with the current state value and a function to update it.
Explain the useEffect Hook
useEffect lets you perform side effects in functional components. It runs after every render and can be used for data fetching
What is the difference between props and state?
Props are read-only and passed from parent to child components. State is mutable and managed within the component itself. Props are immutable
What is JSX?
JSX is a syntax extension for JavaScript that looks like HTML and makes it easier to write and add HTML in React. It gets transformed to regular JavaScript function calls.
What is the virtual DOM?
The virtual DOM is a lightweight copy of the actual DOM. React uses it to improve performance by minimizing direct manipulation of the DOM and efficiently updating only the necessary parts.
Explain the React component lifecycle
The React lifecycle is divided into three main phases:
Initialization phase: This is the stage where the component is constructed with the given Props and default state. This is done in the constructor of a Component Class.
Mounting Phase: This phase begins when a component is created and inserted into the DOM.
Updating Phase: This occurs when a component is re-rendered due to changes in props or state.
Unmounting Phase: This is the final phase when a component is removed from the DOM.
The component lifecycle consists of mounting (adding to the DOM)
What is prop drilling? How can you avoid it?
Prop drilling occurs when props are passed through multiple levels of components. It can be avoided using Context API
What is the Context API?
Context provides a way to pass data through the component tree without manually passing props at every level. It’s an alternative to prop drilling.
How do you handle forms in React?
Forms can be controlled by storing form data in component state and updating it with onChange handlers. React uses synthetic events to handle form submissions.
What is the difference between controlled and uncontrolled components?
Controlled components have their state managed by React
What is the purpose of useReducer Hook?
useReducer is an alternative to useState for complex state logic. It’s preferable when you have multiple sub-values or when the next state depends on the previous one.
Explain React.memo
React.memo is a higher-order component that prevents unnecessary re-renders of functional components by doing a shallow comparison of props.
What is the key prop in React lists?
The key prop helps React identify which items have changed
How does React handle performance optimization?
React uses techniques like virtual DOM