Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

90
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!