React Flashcards
What is React and why is it used?
React is a JavaScript library developed by Facebook for building user interfaces, especially single-page applications. It excels in building reusable component-based UIs.
What is JSX?
JSX stands for JavaScript XML. It’s a syntax extension for JavaScript that allows you to write HTML-like code inside JavaScript. It gets transpiled to React.createElement() calls in the background.
How does React’s virtual DOM work?
The virtual DOM is an in-memory representation of the real DOM. When the state of an object changes, React creates a new virtual DOM and compares it with the old one (diffing). Then it updates the real DOM in the most efficient way possible.
What are props and state in React?
Props (short for “properties”) are a way of passing data from parent to child components. They are read-only.
State is data that a component maintains and can change over time. Changes in state trigger a re-render of the component.
What are React Hooks?
Hooks are functions that let you use state and other React features without writing a class. Common hooks include useState, useEffect, and useContext.
Explain the lifecycle methods in class components.
Lifecycle methods are special methods that automatically get called as your component achieves certain milestones. Key methods include componentDidMount, shouldComponentUpdate, and componentWillUnmount.
How do you handle events in React?
In React, you handle events using camelCase, not lowercase. With JSX you pass a function as the event handler, rather than a string.
What is context in React?
Context provides a way to pass data through the component tree without having to pass props down manually at every level. Useful when certain props (e.g., locale preference, theme) are required by many components.
Explain the difference between a class component and a functional component.
In a functional component you can use state hooks to pass around data whereas in class you need to use props. In a functional component you can use useEffect for mounting versus having to use multiple mount functions like in class components.