Comments (6)
<td>
要素を一つ持つコンポーネント
state 中にマルかバツのテキストを持つ
from bootcampreacttictactoe.
親のゲームボードからマスの state を参照できる形にしなくてはならない
解決策の候補
useContext
- 子に親の state を更新するコールバック関数を props を通じて渡す
from bootcampreacttictactoe.
useContext
を使えば、親コンポーネントの state と setState 関数を一度に子のコンポーネントに渡すことができる
from bootcampreacttictactoe.
GameBoard
コンポーネントのfilledBy
state を、Box
コンポーネントから設定
filledBy
はゲームのマス分の長さを持った String 型のリスト
Box
がリストのどのインデックスの値を変更するかは props から指定
from bootcampreacttictactoe.
onClick
にsetState
(を呼び出す)関数そのものではなく、その返り値を指定した場合、render
内で state を更新することになり、無限ループしてしまう。
from bootcampreacttictactoe.
//これだと、splice が破壊的なのでダメ
// filledBy を直接編集していることになってしまう
filledBy.splice(filledByIndex,1,currentPlayer)
setFilledBy(filledBy)
from bootcampreacttictactoe.
Related Issues (4)
- マルバツゲームのロジックを追加する
- 先行のプレイヤーを選べるようにする HOT 2
- マスを見やすくする HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bootcampreacttictactoe.