For new code, write function components with Hooks. The React documentation says class components are still supported but are not recommended in new code, and this guide shows where that leaves the large class-based codebases most enterprises still run. The practical question for a CTO or platform lead is not which style is "better" but which classes to keep, which to migrate, and how to stop new ones appearing.
Two things still need a class today: error boundaries and getSnapshotBeforeUpdate. Most other class features have a Hooks equivalent. If you are also deciding how to write and test components, see our guides on React without JSX and unit testing in React.
What does React say about function and class components going into 2027?
The React documentation recommends defining components as functions instead of classes. Component and PureComponent sit under the Legacy APIs page, which says they are exported from the react package but are not recommended for newly written code. The latest React release listed on react.dev is 19.3, dated 9 September 2026.
| Item | Current status | Source |
|---|---|---|
| Class components | Still supported, not recommended in new code | react.dev/reference/react/Component |
| Component, PureComponent | Listed under Legacy APIs, not recommended for new code | react.dev/reference/react/legacy |
| Hooks inside classes | Not supported; Hooks work only in function components | react.dev/reference/react/Component |
| componentWillMount, componentWillReceiveProps, componentWillUpdate | Old names deprecated; UNSAFE_ names exist for historical reasons only | react.dev/reference/react/Component |
| contextTypes, getChildContext, string refs | Removed in React 19 for classes | react.dev/blog/2024/04/25/react-19-upgrade-guide |
| defaultProps on classes | Still supported; removed for function components | react.dev/blog/2024/04/25/react-19-upgrade-guide |
| Error boundaries | Still need a class; no function-component equivalent yet | react.dev/reference/react/Component |
How do functional and class components differ in code?
Both take props and return UI. A function component is a plain function. A class component extends React.Component, reads props from this.props and returns UI from render(). State, lifecycle and refs are where the models diverge.
Declaring a component and reading props
function Greeting({ name }) {
return <h1>Hello, {name}</h1>;
}
class Greeting extends React.Component {
render() {
return <h1>Hello, {this.props.name}</h1>;
}
}Holding state
A function component calls useState at the top level of the component. A class declares this.state in a constructor and updates it with this.setState. The two counters below behave the same; the function version is shorter and has no this to bind.
function Counter() {
const [count, setCount] = React.useState(0);
return (
<button onClick={() => setCount(c => c + 1)}>
Clicked {count} times
</button>
);
}
class Counter extends React.Component {
constructor(props) {
super(props);
this.state = { count: 0 };
}
render() {
return (
<button onClick={() => this.setState(s => ({ count: s.count + 1 }))}>
Clicked {this.state.count} times
</button>
);
}
}Lifecycle
React documents that defining componentDidMount, componentDidUpdate and componentWillUnmount together is equivalent to calling useEffect in many cases. In the rare cases where code must run before the browser paints, useLayoutEffect is the closer match. A class component can read only one context at a time.
| Need | Class component | Function component |
|---|---|---|
| State | this.state, this.setState | useState, useReducer |
| Side effects | componentDidMount, componentDidUpdate, componentWillUnmount | useEffect (useLayoutEffect before paint) |
| Skip re-renders | PureComponent, shouldComponentUpdate | memo, or React Compiler where enabled |
| Context | static contextType (one context) | useContext |
| Error boundary | componentDidCatch, static getDerivedStateFromError | No equivalent yet; keep one class |
| Snapshot before DOM update | getSnapshotBeforeUpdate | No equivalent yet; keep a class |
When do class components still make sense?
Error boundaries are the main case. React documents that there is currently no way to write an error boundary as a function component, and suggests writing one ErrorBoundary class yourself or using the react-error-boundary package. Error boundaries do not catch errors in event handlers, server-side rendering or asynchronous code such as setTimeout callbacks. Our older guide covers error handling in React 16; the boundary pattern it describes still applies.
The second case is existing code. Class components are still supported, so a working class that nobody is changing carries no urgency. The third is getSnapshotBeforeUpdate, for which React says there is no function-component equivalent yet.
Are functional components faster?
Not by virtue of syntax. The pages we reviewed on react.dev do not claim that function components render faster than classes. Performance depends on how much work a render does and how often it runs. For skipping re-renders, memo is the function-component counterpart to PureComponent. The React documentation also states that React Compiler automatically applies the equivalent of memo to components, so when you enable it you typically do not need React.memo any more. For measured gains, profile first; see our guide to optimising React application performance.
How should you choose for each component?
| Situation | Choose | Why |
|---|---|---|
| New component | Function component with Hooks | Matches the React recommendation; avoids adding legacy code |
| Error boundary | Class component, one shared instance | Only supported way today; wrap once and reuse |
| Stable class nobody is editing | Leave as is | Still supported; rewriting adds risk and cost without a feature gain |
| Class you are about to change substantially | Migrate while you are in the file | Spreads the cost across planned work |
| Class using UNSAFE_ lifecycles or removed React 19 APIs | Migrate before upgrading to React 19 | Legacy context and string refs were removed for classes |
| Class using getSnapshotBeforeUpdate | Keep the class | No function equivalent yet |
What is a safe migration sequence for an enterprise codebase?
1. Stop the flow of new classes
Add a lint rule or review checklist so new components are functions. This is the cheapest control and needs no rewrite.

2. Clear what blocks upgrades
Inventory classes that use legacy context, string refs or the renamed lifecycle methods. React provides a rename-unsafe-lifecycles codemod for the lifecycle renames. Replace propTypes with a type system such as TypeScript, because React 19 no longer checks them. Our React project structure guide covers how to organise the result.
3. Migrate when you touch the file
Convert a class when you are already changing it, and cover it with tests first. Tests that render and interact with the component, rather than inspect its internals, survive the rewrite; our guide to unit testing in React explains the options, and AgentQA offers quality assurance for agent workflows, outputs and regression risk where your front end drives AI agents.
4. Keep one error boundary
Retain a single class-based boundary, or adopt react-error-boundary, and do not count it as migration debt.
Governance and cost
The main cost is engineering time, so tie migration to planned work rather than a standalone project. The main risk is a blocked upgrade, so track classes that use removed APIs. If your teams also build agent-driven interfaces, ElixirClaw is an agentic OS platform to build, orchestrate and govern AI agents and automation workflows while keeping humans in control. For help scoping React work, see our React.JS application development services.
Key takeaways on React component types
Write new components as functions with Hooks. Keep working classes until you have a reason to change them. Keep one class for error boundaries. Remove blockers such as legacy context, string refs and propTypes before moving to React 19.
To map one front-end or agent decision your teams own, and the context and policy it depends on, book a Context Workshop. See what happens in the workshop.
What should you plan for in 2027?
The choices that matter for the year ahead are the ones the guide already sets out, so build them into your planning rather than treating them as a one off rewrite.
- Stop new classes. Add a lint rule or review checklist so every new component is a function with Hooks.
- Clear upgrade blockers. Inventory classes that use legacy context, string refs or the renamed lifecycle methods, and replace propTypes with a type system before moving to React 19.
- Migrate with planned work. Convert a class when you are already changing it, keep one class based error boundary, and leave stable classes alone.
Tie each step to work already on the roadmap so the cost stays small and the risk of a blocked upgrade stays visible.
Frequently asked questions about functional and class components
Are class components deprecated in React?
The React documentation says class components are still supported but are not recommended in new code. The page does not say they will be removed. Some class features were removed in React 19, such as legacy context and string refs.
Can function components do everything class components can?
Almost. React documents that there is currently no function-component equivalent for error boundaries or getSnapshotBeforeUpdate, so those still need a class.
Do Hooks work inside class components?
No. React documents that Hooks are not supported inside class components.
Should we rewrite all our class components?
React does not require it, and this is our recommendation rather than a React rule: migrate classes when you change them, and prioritise those using APIs removed in React 19.
Is useEffect the same as componentDidMount?
React says defining componentDidMount, componentDidUpdate and componentWillUnmount together is equivalent to calling useEffect in many cases, and useLayoutEffect is closer when code must run before browser paint.
Next Steps for Implementing Functional and Class Components
Talk to our experts about implementing React functional components and class components, how different industries and departments use React components to enhance decision-making. Leverage React Hooks to automate and optimize operations, improving efficiency and responsiveness, similar to how stateful components and stateless components are managed in React.
Follow XenonStack on LinkedIn: XenonStack on LinkedIn for new guides on agentic AI, data and platform engineering.
Explore the XenonStack platform family: ElixirData · ElixirClaw · ElixirHub · NexaStack · MetaSecure · Neural AI · AgentGRC · AgentSRE · AgentAnalyst · AgentInstruct · AgentRAI · AgentScrum · AgentSearch · AgentForce · AI Aviator · SAIF Aviator · CohortIQ · XenonStack AI · XenonStack UAE