defaultProps in React Native?

后端 未结 3 2159
终归单人心
终归单人心 2021-01-06 01:02

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

<         


        
3条回答
  •  心在旅途
    2021-01-06 01:52

    I always do it like this and it works just fine:

    class Foo extends React.Component {};
    
    Foo.propTypes = {
      animateBackground: PropTypes.bool
    };
    
    Foo.defaultProps = {
      animateBackground: false
    };
    
    export default Foo;
    

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题