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

159
Visualizações
Color not rendering from props

So, I'm passing in props to my JSX component, and then setting that props into a gradient from black to that prop. But whenever I try this, the gradient ends up going from black to just a transparent background.

import React from 'react'

import Color from './color'

const App = () => {
    return (
        <div className="h-screen w-screen">
            <Color color="red-400" />
        </div>
    )
}

export default App

import React from 'react'

const color = props => {


    return (
        <div className="h-screen w-screen">
            <div className={`h-full w-full absolute bg-gradient-to-r from-cyan-500 to-${props.color}`}>
                {props.text}
            </div>
        </div>
    )
}

export default color

What should I do?

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

0

Tailwind statically scans your files. It cannot interpolate strings. So whenever you pass a class, you have the pass the whole thing. 'to-red-500' instead of `to-${'red-500'}`

Following changes should make it work(should probably update the prop name from color to say tocolor):

import React from 'react'

import Color from './color'

const App = () => {
    return (
        <div className="h-screen w-screen">
            <Color color="to-red-400" />
        </div>
    )
}

export default App
import React from 'react'

const color = props => {


    return (
        <div className="h-screen w-screen">
            <div className={`h-full w-full absolute bg-gradient-to-r from-cyan-500 ${props.color}`}>
                {props.text}
            </div>
        </div>
    )
}

export default color
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