How to declare style in propTypes?

Solution 1:

React Native now contains ViewPropTypes, which will replace View.propTypes.style. Example of usage:

import { ViewPropTypes } from 'react-native';

MyComponent.propTypes = {
  style: ViewPropTypes.style
};

Solution 2:

View.propTypes.style

or

Text.propTypes.style

It would look like this:

DEMO.propTypes = {
    style: Text.propTypes.style,
    ...
};

https://facebook.github.io/react-native/releases/0.21/docs/style.html#pass-styles-around

Solution 3:

One possibility is to use the react-style-proptype package like so:

import stylePropType from 'react-style-proptype';

MyComponent.propTypes = {
  style: stylePropType,
};

Solution 4:

Use the simple code as below.

PropTypes.oneOfType([PropTypes.object, PropTypes.array])

So, you can apply to this your code.

DEMO.propTypes = {
    style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
};

Tested in RN > 0.57.

Solution 5:

Use ViewPropTypes.style. View.propTypes has been deprecated