Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

119
Vistas
Using a ternary expression in React

In this component:

 const MovieComponent = (props) => {
  const { Poster, Price, Title, cinemaWorldPrice } = props.movie;

  return (
    <MovieContainer>
      <CoverImage src={Poster} alt="" />
      <MovieName>{Title}</MovieName>

      <InfoColumn>
        <MovieInfo>FilmWorld: ${Price}</MovieInfo>
        <MovieInfo>CinemaWorld: ${cinemaWorldPrice}</MovieInfo>
      </InfoColumn>
    </MovieContainer>
  );
};

I'm wanting to write a ternary expression that will change the font color of:

<MovieInfo>FilmWorld: ${Price}</MovieInfo>
        <MovieInfo>CinemaWorld: ${Price}</MovieInfo>

Something basically saying

if (Filmworld Price > CinemaWorld Price) { Filmworld Price = color: "green"}

and vice versa. Is this possible? And would the code be in the movie info section? This is on React.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You need to

  • properly interpolate the prices into JSX (${} is only for template literals)
  • surround the price texts in another element, like a span, so you can then conditionally color that span if needed
const MovieComponent = (props) => {
    const { Poster, Price, Title, cinemaWorldPrice } = props.movie;
    return (
        <MovieContainer>
            <CoverImage src={Poster} alt="" />
            <MovieName>{Title}</MovieName>
            <InfoColumn>
            <MovieInfo>
                    FilmWorld:
                    <span style={Price > cinemaWorldPrice ? { color: 'green' } : null}>{Price}</span>
                </MovieInfo>
                <MovieInfo>
                    CinemaWorld:
                    <span style={Price < cinemaWorldPrice ? { color: 'green' } : null}>{cinemaWorldPrice}</span>
                </MovieInfo>
            </InfoColumn>
        </MovieContainer>
    );
};
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda