I want, when I click on an element, a cross appears on this element. But the cross appears on all lines. In the console, I print the coordinates that come into the function, it is clear that they are correct.
Why is this happening and how to fix it?
class App extends React.Component { constructor (props) { super(props); this.state = { data: Array(5).fill(Array(5).fill('О')), }; } onClick = (i, j) => { return () => { let data = this.state.data; console.clear(); console.log(i, j); data[i][j] = 'X'; this.setState({data}); } }; render() { return ( <div className="field"> {this.state.data.map((item, i) => ( <div key={`row-${i}`} className="field__row"> {item.map((item, j) => <div key={`cell-${j}`} onClick={this.onClick(i, j)} className="field__cell">{item}</div>)} </div> ))} </div> ); } } ReactDOM.render(<App />, document.getElementById('root')); .field { font-size: 0; } .field__cell { position: relative; display: table-cell; width: 30px; height: 30px; border: 1px solid black; vertical-align: middle; font-size: 16px; text-align: center; cursor: pointer; } <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script> <div id="root"></div>