When is it important to pass props
to super()
, and why?
class MyComponent extends React.Component {
constructor(props) {
supe
super()
is used to call the parent constructor.
super(props)
would pass props
to the parent constructor.
From your example, super(props)
would call the React.Component
constructor passing in props
as the argument.
More information on super
:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/super