Skip to content

Commit 463640d

Browse files
authored
Merge pull request reactjs#8 from yangshun/constructor-props
Ensure all class constructors call super with props
2 parents 6c19b64 + 7c6f185 commit 463640d

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

content/blog/2015-01-27-react-v0.13.0-beta-1.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ Therefore we decided not to have this built-in into React's class model. You can
8989

9090
```javascript
9191
class Counter extends React.Component {
92-
constructor() {
93-
super();
92+
constructor(props) {
93+
super(props);
9494
this.tick = this.tick.bind(this);
9595
}
9696
tick() {

content/docs/higher-order-components.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ For example, say you have a `CommentList` component that subscribes to an extern
3030

3131
```js
3232
class CommentList extends React.Component {
33-
constructor() {
34-
super();
33+
constructor(props) {
34+
super(props);
3535
this.handleChange = this.handleChange.bind(this);
3636
this.state = {
3737
// "DataSource" is some global data source

content/tutorial/tutorial.md

+16-16
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ First, add a constructor to the class to initialize the state:
200200
201201
```javascript{2-7}
202202
class Square extends React.Component {
203-
constructor() {
204-
super();
203+
constructor(props) {
204+
super(props);
205205
this.state = {
206206
value: null,
207207
};
@@ -228,8 +228,8 @@ Now the `<button>` tag looks like this:
228228
229229
```javascript{10-12}
230230
class Square extends React.Component {
231-
constructor() {
232-
super();
231+
constructor(props) {
232+
super(props);
233233
this.state = {
234234
value: null,
235235
};
@@ -282,8 +282,8 @@ Pulling state upwards like this is common when refactoring React components, so
282282
283283
```javascript{2-7}
284284
class Board extends React.Component {
285-
constructor() {
286-
super();
285+
constructor(props) {
286+
super(props);
287287
this.state = {
288288
squares: Array(9).fill(null),
289289
};
@@ -399,8 +399,8 @@ Try clicking a square – you should get an error because we haven't defined `ha
399399
400400
```javascript{9-13}
401401
class Board extends React.Component {
402-
constructor() {
403-
super();
402+
constructor(props) {
403+
super(props);
404404
this.state = {
405405
squares: Array(9).fill(null),
406406
};
@@ -528,8 +528,8 @@ Let's default the first move to be by 'X'. Modify our starting state in our Boar
528528
529529
```javascript{6}
530530
class Board extends React.Component {
531-
constructor() {
532-
super();
531+
constructor(props) {
532+
super(props);
533533
this.state = {
534534
squares: Array(9).fill(null),
535535
xIsNext: true,
@@ -564,8 +564,8 @@ After these changes you should have this Board component:
564564
565565
```javascript{6,11-16,29}
566566
class Board extends React.Component {
567-
constructor() {
568-
super();
567+
constructor(props) {
568+
super(props);
569569
this.state = {
570570
squares: Array(9).fill(null),
571571
xIsNext: true,
@@ -715,8 +715,8 @@ First, set up the initial state for Game by adding a constructor to it:
715715
716716
```javascript{2-10}
717717
class Game extends React.Component {
718-
constructor() {
719-
super();
718+
constructor(props) {
719+
super(props);
720720
this.state = {
721721
history: [{
722722
squares: Array(9).fill(null),
@@ -1006,8 +1006,8 @@ First, add `stepNumber: 0` to the initial state in Game's `constructor`:
10061006

10071007
```js{8}
10081008
class Game extends React.Component {
1009-
constructor() {
1010-
super();
1009+
constructor(props) {
1010+
super(props);
10111011
this.state = {
10121012
history: [{
10131013
squares: Array(9).fill(null),

0 commit comments

Comments
 (0)