Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

105
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!