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

How to check data type in C++? -

javascript - Is getTimezoneOffset() stable during daylight saving transition? -

formula - R: how to pass in a reference to the variable in glm or lm? -