Let’s examine the Row
component, stored in components/Row.js
:
import React from 'react'
import Cell from './Cell'
const Row = (props) => {
const cells = []
const y = props.y
for (let x = 0; x < props.x; x += 1) {
cells.push(
<Cell
key={`${x}-${y}`}
y={y}
x={x}
onChangedValue={props.handleChangedCell}
updateCells={props.updateCells}
value={props.rowData[x] || ''}
/>,
)
}
return (
<div>
{cells}
</div>
)
}
export default Row
Same as the Table
component, here we’re building an array of Cell
components and we put it in the cells
variable, which the component renders.
We pass the x, y coordinates combination as the key, and we pass down as a prop the current state of that cell value using value={props.rowData[x] || ''}
, defaulting the state to an empty string if not set.