What Is New in React 15.0?
React 15 focuses on stability and refinement, removing legacy code and improving compatibility with the web platform. The key updates are summarized below.
| Category | Key Changes |
|---|---|
| Initial Render | Uses document.createElement instead of generating HTML strings. Reduces markup size and improves SVG support. |
| DOM Naming | Standardizes DOM property and attribute names (e.g., className for SVG, htmlFor). |
| Error Handling | Errors inside components no longer corrupt internal state. Errors are logged to console with component stack traces. |
| Component Return Values | Components can now return null, strings, numbers, or arrays of elements from render. |
Extraneous <span>s |
Fewer extraneous wrapper DOM nodes for components returning strings/numbers and in <textarea>. |
| Deprecations | Removed deprecation warnings for LinkedStateMixin and React.createClass factory. These now work without warnings but are discouraged. |
| Add-ons | New React Perf add-on for performance measurement. ReactTestUtils now works with any testing library that supports DOM rendering. |
How did React 15 improve DOM rendering and compatibility?
The core rendering engine got a significant cleanup. Under the hood, React 15 now uses document.createElement for initial renders instead of setting innerHTML. This change brings React's output closer to standard DOM and eliminates a lot of historical workarounds.
In practice, this means generated HTML is cleaner with fewer redundant data attributes. It also unlocks better support for SVG and other non-HTML namespaces right out of the box. You'll see a smaller DOM footprint, which can matter for very large applications.
Standardized DOM Property Names
React now consistently uses the DOM API property names. For example, you use className and htmlFor for both HTML and SVG elements. This removes the mental overhead of remembering different attribute names for SVG.
// Works the same for both <div> and <svg>
<div className="foo" />
<svg className="bar" />
What changed with component return values and wrapper nodes?
Components gained more flexibility in what they can render. The render method can now return strings, numbers, arrays, or null directly.
// Returning a string
render() {
return 'Hello World';
}
// Returning an array
render() {
return [<li key="1"/>, <li key="2"/>];
}
This also reduced the number of extra <span> tags React generated internally. Components returning strings or numbers no longer get a wrapper span, and <textarea> children are handled more cleanly. This leads to a simpler, more predictable DOM tree.
How are errors handled differently in React 15?
Error handling is more robust. Previously, an error thrown during rendering could leave React's internal state corrupted. In React 15, errors are caught at a boundary, logged with a detailed component stack, and the internal state remains intact.
This means a bad component is more likely to fail in isolation without breaking the entire app. The error messages in the console are significantly better, showing the component hierarchy that led to the problem, which speeds up debugging.
What's new for developers using add-ons and testing?
The React Perf add-on was introduced as a standalone package. It gives you precise measurements for component renders, helping you identify performance bottlenecks in your app.
ReactTestUtils was decoupled from the specific testing framework. You can now use it with any library that can render to a real DOM, like Mocha or Tape, not just Jest. This gives teams more flexibility in their testing setup.
Deprecated Patterns
While the deprecated LinkedStateMixin and React.createClass factory still work, their warnings were removed. The team encourages moving to ES6 classes and managing form state manually for clearer code.
FAQ
Is React 15 a complete rewrite from React 0.14?
No, it's not a rewrite. React 15 is an incremental release that builds on 0.14. The major version bump signifies the removal of long-standing deprecations and a commitment to stability for the core API.
Do I need to change my code to upgrade from React 0.14?
Most existing code will work without changes. The breaking changes are minimal and focused on rarely used APIs and internal details. The upgrade path is designed to be smooth.
Why are there fewer extra <span> tags in the DOM now?
React's internal reconciliation process was refined. It no longer needs to wrap primitive return values (strings, numbers) in extra DOM nodes for bookkeeping, resulting in cleaner markup.
Can I use SVG attributes like `class` and `for` now?
No. React continues to use the DOM property names className and htmlFor for consistency across HTML and SVG. The improvement is that these names now work correctly in all contexts.
How do I measure performance in React 15?
Use the new react-addons-perf package. You can call Perf.start() and Perf.stop() around operations, then use methods like Perf.printWasted() to see which components re-rendered unnecessarily.