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
<
You want this:
Foo.propTypes = {
someData: React.PropTypes.string
};
This says that someData should be a string, but it is not required.
Then in your render(), you can do this:
render() {
return (
{this.props.someData || Foo.defaultProps.someData}
);
}
This will use this.props.someData if it's provided or Foo.defaultProps.someData if not.
I also think you need to wrap {this.props.someData || Foo.defaultProps.someData} in a Text element (i.e., ).