Sentry Answers>React Native>

ViewPropTypes will be removed from React Native. Migrate to ViewPropTypes exported from 'deprecated-react-native-prop-types'

ViewPropTypes will be removed from React Native. Migrate to ViewPropTypes exported from 'deprecated-react-native-prop-types'

Matthew C.

The Problem

When running your React Native application, you may get the following warning:

Click to Copy
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:

Click to Copy
ERROR Invariant Violation: ViewPropTypes has been removed from React Native. Migrate to ViewPropTypes exported from 'deprecated-react-native-prop-types'.

The Solution

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:

    Click to Copy
    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:

    Click to Copy
    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.

Note on the History of PropTypes in React

In 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:

  • Developers needed more time to upgrade to the latest React Native version and migrate their code to avoid using PropTypes.
  • There were some issues that prevented developers from fixing the PropTypes depreciation warning.

In React Native version 0.74, the deprecated PropTypes was removed again.

  • Syntax.fm logo
    Listen to the Syntax Podcast

    Tasty treats for web developers brought to you by Sentry. Get tips and tricks from Wes Bos and Scott Tolinski.

    SEE EPISODES

Considered “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.

© 2024 • Sentry is a registered Trademark of Functional Software, Inc.