Is it possible to use defaultProps in React Native? I’ve tried the following 2 ways of defining defaultProps and I get null when trying to access the defaultProp
<
I do it in ReactNative
import React, {
Component
} from 'react';
import {
View,
Text
} from 'react-native';
import PropTypes from 'prop-types';
export default class foo extends Component {
static propTypes = {
name: PropTypes.array,
prop2: PropTypes.string
}
static defaultProps = {
array: [1, 2, 4],
name: 'abc'
}
constructor(props) {
super(props);
this.state = {};
}
render() {
return (
Default Prop array is: {this.props.array}
Default Prop name is: {this.props.name}
);
}
}
And then you can use these props like this.props.prop1
and this.props.prop2
.