As with any major release, there are typically breaking changes. Although the changelog for React states "No New Features" there are a few. The TLDR for this is a preparation for the next version to resolve any issues they foresee in migration to the next major version. I'm going to highlight some changes with React and Create React App that will clean up code and increase some efficiency
Plenty of posts have already summarized this so I'm not gonna spend too much time on this. TLDR:
|New Benefit||Problems it solved|
|No longer need to
||JSX is understood by all files compiled below the root, possibly slightly smaller bundle sizes, and enabled future releases|
react-refresh is the successor for
react-hot-loader. For some time, hot loading in react has been a great developer experience where we can keep our frontend application running and it will refresh when the changes are detected. What react-refresh does is a step further. If you are someone who builds client-side rendered applications and pass around a lot of state management in tools such as react context, redux, apollo, or really any react hooks, changes to your code no longer do a complete page refresh! It stores many of those changes and updates only the changes being made. My coworkers and I will love this because we have quite a bit of complex state management being passed around so we no longer lose our place when we want to make a minor JSX change! Here's a preview
Notice the changes to the return JSX and the imports and it still stores state. Get excited! I am!
npm install email@example.com firstname.lastname@example.org email@example.com
rm -rf node_modules package-lock.json
Although this isn't necessary if you run into any odd eslint related errors I found doing a clean install removed quite a few for me
npm run build
This is really only applicable to typescript projects. There is a flag that you'll see get set and after that...
npm run start
Since create-react-app updated their eslint setup you may see some errors thrown that are new. I just spent the time to understand them and resolve them as I see fit. Some of the rules such as import order we're incorrect because I was using a relative import plugin. If you run into any other problems look for an existing issue or create your own here
If you find an issue that hasn't been captured by the Facebook Create-react-app team here be a good open-source developer and create an issue. I had one where I was referencing an image under my
public/ directory in a sass file to use as a
background-image:... reference when myself and others realized the public directory is no longer available. Read more on this issue here
For most cases, you still would install the updates
npm install firstname.lastname@example.org email@example.com
After that, you would look up your specific platform. Both webpack and babel have plugins to help with the fast refresh and JSX transform config. If you're using other setup's such as react-app-rewired or NextJS refer to their documentation to lookup how others are migrating. It's less common so I am not going to be able to stay up-to-date with the latest way to migrate.