React.js Flashcards
What is React and it’s key features?
A javascript library for building user interfaces.
Key features: virtual DOM, reusable components, unidirectional data flow
What is the React Virtual DOM and how does it work?
A virtual representation of a UI that is kept in memory after the initial render
Any changes are first made to the virtual DOM, then synchronized with the ‘real’ DOM in an efficient way (reconciliation)
Improves performance by only updating the parts that have changed
Describe unidirectional data flow
Data has a single, clear direction of movement throughout the application.
Ensures a predictable and easier-to-understand flow of data, making the application more maintainable and less prone to bugs.
Data Down - data is passed from parent to child
Action up - child doesn’t directly modify the state of its parent; instead, it informs the parent about the desired change
Explain JSX syntax
JSX is a syntax extension for javascript, allowing XML code
Facilitates the creation of react elements in a concise and readable manner
How does React handle data binding?
React uses one-way data binding - where any changes to the data trigger re-renders
What are React props?
Properties - inputs to components, allowing the passing of data from parent to child
Explain state in React
An internal data storage mechanism in React components, when the state changes the component re-renders
Why use key attribute in React lists?
Facilitates efficient updates by identifying which items have changed, been added, or removed.
Controlled vs Uncontrolled
Controlled
* state is controlled by react
* Using useState to manage an input value in order to do something else with it
Uncontrolled
* state is managed by the DOM
*Using useRef to track an input value but doing nothing with it in state
Significance of React Hooks?
Functions (built-in or custom) that allow functional components to use state and lifecycle features
Describe some built-in React Hooks
useState - manage local state.
useEffect - side effects like data fetching, subscriptions, or manually changing the DOM
useMemo - prevents unnecessary recalculations in functional components.
useContext - consume values from the React context without wrapping the component in a context consumer
useReducer - alternative to useState for managing more complex state logic. It is particularly useful when the next state depends on the previous state.
Explain the lifecycle method in a React component
- Mounting - component is created & inserted into the DOM
- Updating - component is re-rendered as a result of changes in props or state
- Unmounting - component is being removed from the DOM
Purpose of React Router?
Simplifies navigation in single-page applications by providing a set of components and hooks to manage routing and rendering based on the current URL
What is Redux?
State management library for larger JS applications
What is React Context?
Provides a way to pass data through the component tree without having to pass props manually at every level
Commonly used with themes, user authentication status, or any other global state across a React component tree