I'm trying to make a tic-tac-toe game in react native. My board is represented by an array in the state:
state = {
tablero : [
[null, null, null],
[null, null, null],
[null, null, null]
],
}
My board component is:
<View>
<View style={styles.fila}>
<Text style={[styles.celda, {borderTopWidth: 0, borderLeftWidth: 0}]}>
{this.state.tablero[0][0]}
</Text>
<Text style={[styles.celda, {borderTopWidth: 0}]}>
{this.state.tablero[0][1]}
</Text>
<Text style={[styles.celda, {borderTopWidth: 0, borderRightWidth: 0}]}>
{this.state.tablero[0][2]}
</Text>
</View>
<View style={styles.fila}>
<Text style={[styles.celda, {borderLeftWidth: 0}]}>
{this.state.tablero[1][0]}
</Text>
<Text style={styles.celda}>
{this.state.tablero[1][1]}
</Text>
<Text style={[styles.celda, {borderRightWidth: 0}]}>
{this.state.tablero[1][2]}
</Text>
</View>
<View style={styles.fila}>
<Text style={[styles.celda, {borderBottomWidth: 0, borderLeftWidth: 0}]}>
{this.state.tablero[2][0]}
</Text>
<Text style={[styles.celda, {borderBottomWidth: 0}]}>
{this.state.tablero[2][1]}
</Text>
<Text style={[styles.celda, {borderBottomWidth: 0, borderRightWidth: 0}]}>
{this.state.tablero[2][2]}
</Text>
</View>
</View>
I want to know how would I update my board when on press. I tried with spread operator but couldnt figure it out