reactjs - Is the call to super(props) in an ES6 class important? -


suppose i've following class:

class tabs extends react.component {   displayname: tabs;    static proptypes = {   selected: react.proptypes.number,   children: react.proptypes.oneoftype([     react.proptypes.array,     react.proptypes.element   ]).isrequired   };    constructor() {   super();   this.state = {     selected: 0,     maxselected: 0   };    render() {     return(       <div>        {this.props.selected}        {this.props.children}       </div>     );   } }; 

i want know if passing following constructor important:

constructor(props) {   super(props); } 

my current code works fine wanted know if practice.

according ben alpert react team it's necessary pass props constructor if intend on using this.props inside constructor. after constructor invoked, react attaches props component outside.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -