My question is simple: How can I handle the value of two child components? Example:
I have this class, Board:
import React, { Component } from 'react';
import Square from './Square';
export default class Board extends Component {
render(){
return (
<>
<Square />
<Square />
</>
);
}
}
and this is the child component:
import React, {useState} from 'react';
const Square = (props) => {
let initStatusMessage = 'Aún no se ha clicado.'
const [count, setCount] = useState(0);
const [status, setStatus] = useState(initStatusMessage);
function handleClick(){
setCount(count + 1);
if(status === initStatusMessage){
setStatus('Veces clicado: ');
}
}
return(
<div>
<p>{status}</p>
<button onClick={() => handleClick()}>{count}</button>
</div>
);
}
export default Square;
How, instead of handling the count value for each of the children, can I handle the different values from the parent?