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

241
Vistas
React hook using useEffect updates on web browser but not on mobile browser

This code works on my desktop browser but not on my mobile browser (Safari or Chrome).

const Board = () => {
    const x=useRecoilValue(nstate);
    const values=useRecoilValue(nspaces);
    const [hash,setHash]=useRecoilState(nplaces);
    const size=Math.sqrt(values.length);
    let bx=Array.from({ length: Math.ceil(values.length / size) }, (v, i) => values.slice(i * size, i * size + size));
    let board=bx.map((item)=> <Fleg>{item.map((x)=> <Col><p><img src={getPhoto(hash[x])} alt=""/></p><p>{Ops(hash,setHash,x)}</p></Col>)}</Fleg>);
    useEffect(() => {
            console.log("show the hash: ",hash);
            board=bx.map((item)=>
                    <Fleg>{item.map((x)=> <Col><p><img src={getPhoto(hash[x])} alt=""/></p><p>{Ops(hash,setHash,x)}</p></Col>)}</Fleg>
            );
    },
    [hash]
    );

    return (
            <>
            {board}
            </>
    );
}

The "hash" is just a dictionary object that has like [0,0]: 1, for all the possible values/positions of the 'board' ( (0,0) through (3,3) ).

If the value is 1, getPhoto(hash[x]) shows a red dot, if 2 a blue dot.

The problem, which only happens on mobile, is that when hash updates, the surrounding 'squares' get updated images, but the current 'square' is not updated.

To me it seems like it should work - hash is being updated, and printing to the console w/the expected values - but the UI doesn't show what hash does. The current 'cell' does not update its image, even after it has changed.

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