Answers for "what is super(props) in react"

1

what is super(props) in react

class App extends React.Component {
  constructor(props) {
      super(props);

      this.state = {};
   }

  // React says we have to define render()
  render() {
    return <div>Hello world</div>;
  }
};
Posted by: Guest on June-12-2020
0

what is super(props) in react

class MyComponent extends React.Component {
  constructor() {
    console.log(this); // Reference Error i.e return undefined
  }

  render() {
    return <div>Hello {this.props.name}</div>;
  }
}
Posted by: Guest on June-12-2020
0

react. why use super(props)

here is only one reason when one needs to pass props to super():

When you want to access this.props in constructor.
Posted by: Guest on July-07-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language