ViewPropTypes will be removed from React Native. Migrate to ViewPropTypes exported from 'deprecated-react-native-prop-types'
Matthew C.
—When running your React Native application, you may get the following warning:
WARN ViewPropTypes will be removed from React Native. Migrate to ViewPropTypes exported from 'deprecated-react-native-prop-types'.
You may also receive the message as an error:
ERROR Invariant Violation: ViewPropTypes has been removed from React Native. Migrate to ViewPropTypes exported from 'deprecated-react-native-prop-types'.
Because React Native started removing the PropTypes
API from version 0.66 onward, an import of PropTypes
results in a deprecation warning.
React Native recommends that you use a type system, such as TypeScript, instead of PropTypes
.
If you need runtime type checking, you can use TypeScript type guards to narrow types down to one specific type at runtime. A library such as tiny-invariant
can further simplify type narrowing.
If you still need to use PropTypes
, install the deprecated-react-native-prop-types
npm package and import the deprecated PropTypes
from deprecated-react-native-prop-types
instead of react-native
.
In other words, you will encounter deprecation warnings and errors when you use the following import:
import { ViewPropTypes } from 'react-native';
But if you install the deprecated-react-native-prop-types
npm package, you can use the following import as a workaround:
import { ViewPropTypes } from 'deprecated-react-native-prop-types';
If you aren’t using Proptypes
, and the warning or error is caused by a dependency, check whether the latest version of the library has fixed the issue.
If your version of the library is already up to date or the latest version hasn’t fixed the imports, submit an issue or pull request to the library.
As a last resort, you can fix the imports in the dependencies yourself. You can use a library such as patch-package
to simplify fixing the imports until they are fixed by the library.
PropTypes
in ReactIn 2017, React version 15.5 moved the built-in PropTypes
to a separate package, because static type checking with TypeScript is used more often than PropTypes
in modern React.
React Native started to remove the PropTypes
API in 2018.
In 2021, a deprecation warning for using PropTypes
was included in the release of React Native version 0.66.
In React Native version 0.68, PropTypes
was removed.
React Native restored PropTypes
in version 0.71 for two reasons:
PropTypes
.PropTypes
depreciation warning. In React Native version 0.74, the deprecated PropTypes
was removed again.
Tasty treats for web developers brought to you by Sentry. Get tips and tricks from Wes Bos and Scott Tolinski.
SEE EPISODESConsidered “not bad” by 4 million developers and more than 100,000 organizations worldwide, Sentry provides code-level observability to many of the world’s best-known companies like Disney, Peloton, Cloudflare, Eventbrite, Slack, Supercell, and Rockstar Games. Each month we process billions of exceptions from the most popular products on the internet.
Here’s a quick look at how Sentry handles your personal information (PII).
×We collect PII about people browsing our website, users of the Sentry service, prospective customers, and people who otherwise interact with us.
What if my PII is included in data sent to Sentry by a Sentry customer (e.g., someone using Sentry to monitor their app)? In this case you have to contact the Sentry customer (e.g., the maker of the app). We do not control the data that is sent to us through the Sentry service for the purposes of application monitoring.
Am I included?We may disclose your PII to the following type of recipients:
You may have the following rights related to your PII:
If you have any questions or concerns about your privacy at Sentry, please email us at compliance@sentry.io.
If you are a California resident, see our Supplemental notice.