Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upgrading a project to React 16 with old dependencies

Tags:

reactjs

I would like to upgrade a project to React 16, because I have some dependencies that already rely on it. However, I'm also tailing a few very old React packages that I have not found the time yet to upgrade to newer releases that do support React 16. Now I need to buy some time.

My project sources have kept up with the newer releases of React, but I wonder if there's anything that would not be possible to resolve for old dependencies that would cause them to remain completely broken with React 16?

like image 723
Filip Dupanović Avatar asked Oct 10 '17 16:10

Filip Dupanović


People also ask

How do I update an existing reacting project?

To update your React version, install the latest versions of the react and react-dom packages by running npm install react@latest react-dom@latest . If you use create-react-app , also update the version of react-scripts . Copied! The command will update the versions of the react-related packages.

How do you update dependencies in react app?

Use npm outdated to discover dependencies that are out of date. Use npm update to perform safe dependency upgrades. Use npm install @latest to upgrade to the latest major version of a package. Use npx npm-check-updates -u and npm install to upgrade all dependencies to their latest major versions.


1 Answers

Following this suggested comment, patching React early on by importing something like the following module before importing olden dependencies should work:

import React from 'react'

import PropTypes from 'prop-types'
import createClass from 'create-react-class'

Object.assign(React, {
  PropTypes,
  createClass
})

For projects that were receiving warnings prior to React 16, these then get resolved.

like image 58
Filip Dupanović Avatar answered Sep 30 '22 15:09

Filip Dupanović