4
votes

I'm writing components for our react-native project

I get this error from prop-types

"Warning: Failed prop type: Invalid prop containerStyle of type number supplied to ImagePicker, expected object."

Simplified example:

common-styles.js

    export const defaultStyle = StyleSheet.create({
      container: {
        color: 'red',
        borderWidth: 2
      }
    });

image-picker.js

    ImagePicker.propTypes = {
      containerStyle: PropTypes.shape(),
    };

app.js

    <ImagePicker containerStyle={styles.defaultStyle} />

What is the PropType for passing Stylesheet variables?

Thank you

2
Where is styles (of containerStyle={styles.defaultStyle}) being defined?acdcjunior
Here are some of the possible solutions. stackoverflow.com/questions/34626298/…Susth
@acdcjunior hello, as mentioned it is from common-syles.jsmjabadilla
@Susth, thanks tried it, although I am getting an error if i use array <ImagePicker containerStyle={[form_input.pads, { borderWidth: 1 }]} />, I'll be checking this again and see if I can workaround the array issuemjabadilla

2 Answers

4
votes
import { ViewPropTypes } from 'react-native';
ImagePicker.propTypes = {
  containerStyle: ViewPropTypes.style,
};

Ref: facebook/react-native /Libraries/Components/View/ViewPropTypes.js

0
votes

It seems that the type number was valid since it's the actual styles are saved in an aggregated styles object. Only the lookup IDs are passed

see StyleSheet documentation here

The correct PropTypes should be

    ImagePicker.propTypes = {
      containerStyle: PropTypes.number,
    };