Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

100
Vistas
useState is working but i dont see the changes

im coding a chess game to learn react. So, i got this on the Board component:

export default () => {
    const[squares,setSquares] = useState([]);
    
    useEffect(() => { 
        let item;
        let squaresAux = [];
        setBoard(FEN).forEach((square,i) => {
            item = {
                value: square,
                pos: getXYPosition(i),
                color: getColor(i)        
            }
            squaresAux.push(item);
        })
        setSquares(squaresAux);
    },[])

   

    const handleClick = () => {
        let update = squares.map(square => {
            square.color = "active";
            return square;
        })

        setSquares(update);

    }

    return(
        <div className="board">
            {squares.map((square) => (  
                <Square handleClick = {handleClick} color={square.color} value={square.value} />
            ))}
        </div>
    );
}

And on the Square component i got this:

import React,{useState} from 'react';

    

export default (props) => {
    const[value,setValue] = useState(props.value);
    const[color,setColor] = useState(props.color);

    const handleClick = () => {
        props.handleClick();
        
    }

    return(
        <div>
            <div className={`cell ${color}`} onClick={() => handleClick()}>{value}</div>
        </div>
    );
}

The idea is that when i click on a square all the squares change their color. The state is changing in both components, also the color state in square is changing, but the visual colors dont. ¿What could be the problem?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda