How to set component default props on React component

后端 未结 9 914
孤街浪徒
孤街浪徒 2020-12-07 13:52

I use the code below to set default props on a React component but it doesn\'t work. In the render() method, I can see the output \"undefined props\" was printe

9条回答
  •  悲哀的现实
    2020-12-07 14:25

    class Example extends React.Component {
      render() {
        return 

    {this.props.text}

    ; } } Example.defaultProps = { text: 'yo' };

提交回复
热议问题