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

153
Visualizações
Passing div style as a function argument Javascript/ React

I'm building an application using React, framer-motion and react-intersection-observer. Inside animation.js I have a function which is imported inside App.js and used as a component in App.js.

I want to apply an aspect ratio to some divs using style as a parameter, but it doesn't work.

<FadeAnimation name={'project-image--image'} style={'--ratio':16/9} />



Failed to set an indexed property on 'CSSStyleDeclaration': Indexed property setter is not supported.

I have other divs with this property and they are displayed correctly

<div className='project-image--image' style={{'--ratio':1/2}}/>

Animation.js

export const container = {
  hidden: { opacity: 0, y: 5 },
  visible: { opacity: 1, y: 0 }
}

function FadeAnimation({ children, name, delay, duration, style }) {
  const controls = useAnimation();
  const [ref, inView] = useInView();

  useEffect(() => {
    if (inView) {
      controls.start("visible");
    }
  }, [controls, inView]);

  return (
    <motion.div className={`${name}`} style={{`${style}`}}
      ref={ref}
      animate={controls}
      initial="hidden"
      transition={{ duration: duration, delay: delay }}
      variants={{
        visible: { opacity: 1, y: 0 },
        hidden: { opacity: 0, y: 5 }
      }}
    >
      {children}
    </motion.div>
  );
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Have you tried:

<FadeAnimation name={'project-image--image'} style={{'--ratio':16/9}} />

(Adding another curly brace)

And then, in the FadeAnimationComponent using it as

<motion.div className={`${name}`} style={style} {/*...*/}/>
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