React, why use super(props) inside of ES6 class constructor? [duplicate]












12
















This question already has an answer here:




  • What's the difference between “super()” and “super(props)” in React when using es6 classes?

    10 answers




I realize the super keyword can be used to call functions in a parent component. However, I'm not totally clear why you would use the super keyword in the example below - just passing it whatever props are being passed to the constructor.



Can someone please shed some light on the various reasons for using the super keyword in an ES6 class constructor, in react?



  constructor(props) {
super(props);

this.state = {
course: Object.assign({}, this.props.course),
errors: { }
};

this.updateCourseState = this.updateCourseState.bind(this);
}









share|improve this question













marked as duplicate by Bergi ecmascript-6
Users with the  ecmascript-6 badge can single-handedly close ecmascript-6 questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jun 17 '16 at 22:55


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • It would be helpful to see the class declaration. e.g. class SpecialDialog extends Dialog {

    – Conspicuous Compiler
    Jun 17 '16 at 22:29
















12
















This question already has an answer here:




  • What's the difference between “super()” and “super(props)” in React when using es6 classes?

    10 answers




I realize the super keyword can be used to call functions in a parent component. However, I'm not totally clear why you would use the super keyword in the example below - just passing it whatever props are being passed to the constructor.



Can someone please shed some light on the various reasons for using the super keyword in an ES6 class constructor, in react?



  constructor(props) {
super(props);

this.state = {
course: Object.assign({}, this.props.course),
errors: { }
};

this.updateCourseState = this.updateCourseState.bind(this);
}









share|improve this question













marked as duplicate by Bergi ecmascript-6
Users with the  ecmascript-6 badge can single-handedly close ecmascript-6 questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jun 17 '16 at 22:55


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • It would be helpful to see the class declaration. e.g. class SpecialDialog extends Dialog {

    – Conspicuous Compiler
    Jun 17 '16 at 22:29














12












12








12


10







This question already has an answer here:




  • What's the difference between “super()” and “super(props)” in React when using es6 classes?

    10 answers




I realize the super keyword can be used to call functions in a parent component. However, I'm not totally clear why you would use the super keyword in the example below - just passing it whatever props are being passed to the constructor.



Can someone please shed some light on the various reasons for using the super keyword in an ES6 class constructor, in react?



  constructor(props) {
super(props);

this.state = {
course: Object.assign({}, this.props.course),
errors: { }
};

this.updateCourseState = this.updateCourseState.bind(this);
}









share|improve this question















This question already has an answer here:




  • What's the difference between “super()” and “super(props)” in React when using es6 classes?

    10 answers




I realize the super keyword can be used to call functions in a parent component. However, I'm not totally clear why you would use the super keyword in the example below - just passing it whatever props are being passed to the constructor.



Can someone please shed some light on the various reasons for using the super keyword in an ES6 class constructor, in react?



  constructor(props) {
super(props);

this.state = {
course: Object.assign({}, this.props.course),
errors: { }
};

this.updateCourseState = this.updateCourseState.bind(this);
}




This question already has an answer here:




  • What's the difference between “super()” and “super(props)” in React when using es6 classes?

    10 answers








reactjs ecmascript-6 super






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jun 17 '16 at 22:26









malexandersmalexanders

9472935




9472935




marked as duplicate by Bergi ecmascript-6
Users with the  ecmascript-6 badge can single-handedly close ecmascript-6 questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jun 17 '16 at 22:55


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Bergi ecmascript-6
Users with the  ecmascript-6 badge can single-handedly close ecmascript-6 questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jun 17 '16 at 22:55


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • It would be helpful to see the class declaration. e.g. class SpecialDialog extends Dialog {

    – Conspicuous Compiler
    Jun 17 '16 at 22:29



















  • It would be helpful to see the class declaration. e.g. class SpecialDialog extends Dialog {

    – Conspicuous Compiler
    Jun 17 '16 at 22:29

















It would be helpful to see the class declaration. e.g. class SpecialDialog extends Dialog {

– Conspicuous Compiler
Jun 17 '16 at 22:29





It would be helpful to see the class declaration. e.g. class SpecialDialog extends Dialog {

– Conspicuous Compiler
Jun 17 '16 at 22:29












1 Answer
1






active

oldest

votes


















26














super allows you to access the constructor method of the parent class. The only reason to include props is to access this.props inside of your constructor.



What's the difference between "super()" and "super(props)" in React when using es6 classes?






share|improve this answer


























  • Great thanks. that answers my question.

    – malexanders
    Jun 17 '16 at 22:36






  • 2





    Can someone expand on this a bit? So React.Component has its own constructor method, and we use super() to trigger that?

    – corysimmons
    Dec 6 '17 at 20:08


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









26














super allows you to access the constructor method of the parent class. The only reason to include props is to access this.props inside of your constructor.



What's the difference between "super()" and "super(props)" in React when using es6 classes?






share|improve this answer


























  • Great thanks. that answers my question.

    – malexanders
    Jun 17 '16 at 22:36






  • 2





    Can someone expand on this a bit? So React.Component has its own constructor method, and we use super() to trigger that?

    – corysimmons
    Dec 6 '17 at 20:08
















26














super allows you to access the constructor method of the parent class. The only reason to include props is to access this.props inside of your constructor.



What's the difference between "super()" and "super(props)" in React when using es6 classes?






share|improve this answer


























  • Great thanks. that answers my question.

    – malexanders
    Jun 17 '16 at 22:36






  • 2





    Can someone expand on this a bit? So React.Component has its own constructor method, and we use super() to trigger that?

    – corysimmons
    Dec 6 '17 at 20:08














26












26








26







super allows you to access the constructor method of the parent class. The only reason to include props is to access this.props inside of your constructor.



What's the difference between "super()" and "super(props)" in React when using es6 classes?






share|improve this answer















super allows you to access the constructor method of the parent class. The only reason to include props is to access this.props inside of your constructor.



What's the difference between "super()" and "super(props)" in React when using es6 classes?







share|improve this answer














share|improve this answer



share|improve this answer








edited May 23 '17 at 12:34









Community

11




11










answered Jun 17 '16 at 22:30









jmancherjejmancherje

3,33631944




3,33631944













  • Great thanks. that answers my question.

    – malexanders
    Jun 17 '16 at 22:36






  • 2





    Can someone expand on this a bit? So React.Component has its own constructor method, and we use super() to trigger that?

    – corysimmons
    Dec 6 '17 at 20:08



















  • Great thanks. that answers my question.

    – malexanders
    Jun 17 '16 at 22:36






  • 2





    Can someone expand on this a bit? So React.Component has its own constructor method, and we use super() to trigger that?

    – corysimmons
    Dec 6 '17 at 20:08

















Great thanks. that answers my question.

– malexanders
Jun 17 '16 at 22:36





Great thanks. that answers my question.

– malexanders
Jun 17 '16 at 22:36




2




2





Can someone expand on this a bit? So React.Component has its own constructor method, and we use super() to trigger that?

– corysimmons
Dec 6 '17 at 20:08





Can someone expand on this a bit? So React.Component has its own constructor method, and we use super() to trigger that?

– corysimmons
Dec 6 '17 at 20:08





Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas