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

180
Visualizações
Is there are way to force GatsbyImage to re-render when it's imgStyle is changed?

I made a deck of cards, where one card is "currently selected." The images of the remaining cards get blurred. I achieve this using a "disabled" prop passed to my project card component and the following conditional styles which get passed to my GatsbyImage:

let blurAmount = disabled ? '3px' : '0px';
const imgStyle = { 
    imagePosition: "center",
    borderRadius: "2%",
    filter: `blur(${blurAmount})`
}

const staticImage = (
    <GatsbyImage
    image={data.preview[0].gatsbyImageData}
    alt={data.preview[0].description}
    imgStyle={imgStyle}/>
)

The "current card" state is controlled in the parent component which loops through the queried data and creates the card deck. On the first render, this works as expected, but the when I change the current index with my toggle component, the blurred images remain blurred, and the clear image remains clear. I logged the value of blurAmount above, and it changes appropriately. This leads me to believe that once a GatsbyImage component is created from some gatsbyImageData, it's "immutable." Is this understanding correct, and is there a work around (other than storing blurred images in my CMS).

Here is a picture of the error. The current card is the second one, but it is still blurred, and the first card's image is still clear. https://imgur.com/a/24dXtr7

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I will suggest you to redo the component and pass blurAmount as a prop and use a useState to store the value, and then with the useEffect hook re-render every time that value changes

useEffect(() => {
  // save in state
}, [blurAmount]);
about 4 years ago · Juan Pablo Isaza Relatório
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