What’s new in React 17: new features and improvements

React.js version 17 was released in October 2020 and introduced several new features and improvements. In this blog post, we’ll explore the major updates in React.js version 17.

No More Event Pooling

One of the most significant changes in React.js version 17 is the removal of the event pooling optimization. Previously, React.js used a technique called “event pooling” to reduce the number of event objects created by the browser. However, this technique had some drawbacks, such as preventing the use of asynchronous event handlers and making the code more difficult to reason about.

With React.js version 17, the event pooling optimization has been removed, and every event object is now a unique instance. This change allows developers to use asynchronous event handlers and makes it easier to reason about the behavior of event handling in React.js.

Changes to React’s Tree Reconciliation Algorithm

React.js version 17 also introduces some changes to its tree reconciliation algorithm. Previously, React.js used an algorithm that compared the virtual DOM tree of the previous and current states of the application and updated the real DOM accordingly.

With React.js version 17, the reconciliation algorithm has been updated to be more efficient and to better support the use of custom renderers. Specifically, the new algorithm only updates the parts of the tree that have changed, rather than the entire tree.

Improved Error Handling

Another significant update in React.js version 17 is the improved error handling. Previously, when an error occurred in a component, React.js would unmount the component and its children, making it difficult to diagnose the error and fix the issue.

With React.js version 17, errors are now caught and handled more gracefully. Components that encounter an error will remain mounted, and developers can use error boundaries to catch and handle errors in a more controlled way.

Improved Support for Portals

React.js version 17 also includes some improvements to the support for portals, which allow developers to render a component in a different part of the DOM tree. Previously, portals could cause issues with event handling and other aspects of the React.js lifecycle.

With React.js version 17, portals are now better integrated into the React.js lifecycle and have improved support for event handling.

Conclusion

React.js version 17 includes several new features and improvements, including the removal of event pooling, updates to the tree reconciliation algorithm, improved error handling, and better support for portals. These updates improve the performance and reliability of React.js and make it easier for developers to build complex applications

If you are interested in new React features and patterns, I’m finishing publishing with Manning Publications an update to my book React Quickly.

Author: Azat

Techies, entrepreneur, 20+ years in tech/IT/software/web development expert: NodeJS, JavaScript, MongoDB, Ruby on Rails, PHP, SQL, HTML, CSS. 500 Startups (batch Fall 2011) alumnus. http://azat.co http://github.com/azat-co

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.