Component Patterns

Component Patterns

Delve into advanced React concepts, including component patterns and the introduction of server components in React 19. Understanding these advanced features will empower you to build scalable and maintainable applications.

8 audio · 1:28

Nortren·

What is a higher-order component?

0:11
A higher-order component, or HOC, is a function that takes a component and returns a new component with additional props or behavior. It is a pattern for reusing component logic, though hooks have largely replaced it in modern React.

What is the render props pattern?

0:10
The render props pattern is a technique where a component accepts a function as a prop and calls it to determine what to render. It allows sharing logic between components by passing rendering responsibility to the consumer.

What is forwardRef in React?

0:11
forwardRef is a function that lets a component receive a ref from its parent and forward it to a DOM element or another component. It is useful for wrapper components that need to expose an underlying element to their consumers.

What is an error boundary?

0:13
An error boundary is a class component that catches JavaScript errors anywhere in its child component tree during rendering, in lifecycle methods, and in constructors. It logs the error and displays a fallback UI instead of crashing the whole app.

Why must error boundaries be class components?

0:10
As of current React versions, only class components can implement the componentDidCatch and getDerivedStateFromError lifecycle methods required to catch errors. There is no hook equivalent yet.

What do error boundaries not catch?

0:11
Error boundaries do not catch errors inside event handlers, asynchronous code like setTimeout callbacks, server-side rendering, or errors thrown in the error boundary itself. Those must be handled with regular try-catch blocks.

What is a React portal?

0:10
A portal lets you render a child component into a DOM node outside of the parent component's DOM hierarchy. It is commonly used for modals, tooltips, and overlays that must visually escape their container.

What is a pure function and why does React expect components to be pure?

0:12
A pure function always returns the same output for the same input and has no side effects. React expects components to be pure during rendering so it can safely re-run them, skip updates, and enable concurrent features without causing bugs. ---