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

320
Views
Get rid of warning when dynamically rendering React styled component

I'm getting the following warning in the browser console:

react_devtools_backend.js:3973 The component styled.div with the id of "sc-dmRaPn" has been created dynamically.
You may see this warning because you've called styled inside another component.
To resolve this only create new StyledComponents outside of any render method and function component.

However, my CSS positioning is supposed to be dynamic. The height changes every 5 seconds.

Can I do any of the following?

  1. Code it properly so it wont show the warning
  2. Or, suppress the warning in case 1 is not possible
// Height of the div is dynamically calculated every 5 seconds
private randomHeight = () => {
    return Math.floor(Math.random() * 85);
}

// This method is eventually called by the Render method
private getLeftDiv = () => {
    const height = this.randomHeight();

    const keyFrames = keyframes`
          0% {
              left: -120px;
          }
          5% {
              left: -45px;                
          }
          95% {
              left: -45px;                
          } 
          100% {
              left: -120px;
          }
      `
    const HeadDiv = styled.div`
          position: fixed;
          animation: ${keyFrames} 2s linear;
          animation-timing-function: ease-in ;
          left: -120px;
          top: ${height}%;
          transform: rotate(45deg);
      `
    return HeadDiv;
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You should declare the HeadDiv styled component separately outside of the current component's render, and use its props to pass the dynamic values to it.

const HeadDiv = styled.div`
    position: fixed;
    animation: ${props => props.keyFrames} 2s linear;
    animation-timing-function: ease-in ;
    left: -120px;
    top: ${props => props.height}%;
    transform: rotate(45deg);
`

You can now pass the dynamic values to HeadDiv's props.

<HeadDiv keyFrames={keyFrames} height={height} />
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!