私はReact.jsのチュートリアルを、以下の、そして私はReact.Component
のrender
メソッド内で次のコードスニペットを参照してくださいhttps://reactjs.org/tutorial/tutorial.html#showing-the-movesでいますよ:ここ2つの入力を持つ矢印関数を持つArray.prototype.map()呼び出しの目的は何ですか?
const moves = history.map((step, move) => {
const desc = move ?
'Go to move #' + move :
'Go to game start';
return (
<li>
<button onClick={() => this.jumpTo(move)}>{desc}</button>
</li>
);
});
、history
が持つオブジェクトの配列ですsquare
プロパティ:
history = [
{
squares: [
null, null, null,
null, null, null,
null, null, null,
]
},
{
squares: [
null, null, null,
null, 'X', null,
null, null, null,
]
},
// ...
]
history.map
の矢印関数は、2つの入力、step
とmove
を持って、なぜ私は理解していないことです。 map
、https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/mapのドキュメントでは、1つの入力(問題の配列要素)を持つ矢印関数の例しか表示されません。私はstep
の入力が矢印メソッドの本体のどこにでも使われていないので、目的が何であるか分かりません。誰かがこれを説明できますか?
そのドキュメントの "パラメータ" セクションの下をご覧ください。コールバックは、currentValue、index、およびarrayの3つの引数を受け入れることができます。 'step'はcurrentValue、' move'はインデックスです。 – Andy