Skip to content

Commit 15c5b0b

Browse files
committed
understanding super and props system
Signed-off-by: Tathagat Thapliyal <[email protected]>
1 parent 8773885 commit 15c5b0b

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

src/components/Board.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import React from 'react'
22
import Square from './Square'
33

4-
export default function Board() {
4+
export default function Board(props) {
55
return (
66
<div>
77
<div className="border-row">
8-
<Square/>
8+
<Square insideValue = {props.value}/>
99
<Square/>
1010
<Square/>
1111
</div>

src/components/Game.js

+12-6
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,27 @@ import React from 'react'
22
import Board from './Board'
33

44
export default class Game extends React.Component {
5-
constructor() {
6-
super()
5+
constructor(props) {
6+
super(props)
77
this.state = {
88
xIsNext: true,
99
stepNumber: 0,
1010
history: [
1111
{squares: Array(9).fill(null)}
12-
]
13-
}
14-
}
12+
],
13+
}
14+
}
15+
16+
someFunction = () => {
17+
return 5
18+
}
19+
1520
render() {
21+
const result = this.someFunction()
1622
return(
1723
<div className= "game">
1824
<div className = "game-board">
19-
<Board/>
25+
<Board value = {result}/>
2026
</div>
2127
</div>
2228
)

src/components/Square.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React from 'react'
22

3-
export default function Square() {
3+
export default function Square(props) {
44
return (
55
<button className = "square">
6-
6+
{props.insideValue}
77
</button>
88
)
99
}

0 commit comments

Comments
 (0)