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

92
Visualizações
style tag completely disappears from ReactJS component on render

Here is the code, not sure if this is an issue with React or a simple typo, but as soon as this component renders, the entire style tag disappears. What this code does is change the transform scale every 750ms to a random size between 0 and 0.5, but as stated, it's having an issue even rendering the tag, which is strange.

let styles = { 
    transform: `scale(0.5);` 
}

function changeStyle() {
    var r = -0.1 + Math.random() * (0.2 - 0) + 0;
    styles = { 
        transform: `scale(${r});` 
    };
    setTimeout(changeStyle, 750);
}

changeStyle();

export default class Runaway extends Component {

    componentDidMount() {
        console.log("Booting up Runaway button v1 by Ashe Muller.")
    }

    render() {
        return (
            <div style={{styles}}>
                <text id="shopItemGrid">RUN AWAY</text>
            </div>
        )
    }
}
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

The way the code is structured now, styles would never change, because changeStyle() is never getting called within the component.

Try something like this:

export default class Runaway extends Component {
  constructor() {
      super();
      this.state = {
        transform: 'scale(0.5)'
      }
  }

  handleTransformChange = () => {
    var r = -0.1 + Math.random() * (0.2 - 0) + 0;
    var newTransform = `scale(${r})`;
    this.setState({
      transform: newTransform
    });
  }

  componentDidMount() {
    console.log("Booting up Runaway button v1 by Ashe Muller.")
    this.timer = setInterval(
      () => this.handleTransformChange(),
      750
    );
  }

  componentWillUnmount() {
    clearInterval(this.timer);
  }

  render() {
    let styles = { 
      transform: this.state.transform
    };

    return (
      <div style={styles}>
        <text id="shopItemGrid">RUN AWAY</text>
      </div>
    );
  }
}
about 4 years ago · Juan Pablo Isaza Relatório

0

your let 'styles' is already an object and should be passed as such to your div style:

<div style={styles}>

so that the result would be :

<div style={{ transform: `scale(0.5);` }}>

In your case you're adding a level of object and finally your style looks like this:

style={{ styles : { transform: `scale(0.5);` }}

which is not a valid 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