Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

248
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda