idev0085 / react-boilerplate

0 stars 0 forks source link

Difference Between React 16 and React 17 #103

Open idev0085 opened 2 years ago

idev0085 commented 2 years ago

In React 16 and earlier, React would do document.addEventListener() for most events. React 17 will call rootNode.addEventListener() under the hood instead. This means any event will operate within root DOM, not the main Html DOM

In React 17, the effect cleanup function always runs asynchronously — for example, if the component is unmounting, the cleanup runs after the screen has been updated.

Consistent Errors for Returning Undefined

In React 16 and earlier, returning undefined has always been an error:

function Button() {
  return; // Error: Nothing was returned from render
}

In 17

function Button() {
  // We forgot to write return, so this component returns undefined.
  // React surfaces this as an error instead of ignoring it.
  <button />;
}