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

135
Vistas
display an image in react based on a response

I want to display an icon only if the answer is yes?

{
 <div className={"options"}>
  <img src={iconteleconsult} alt={"teleconsultation"}/>
 </div>
}  
            
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

here is the code sample this will help:

response
    ? <div className={"options"}>
        <img src={iconteleconsult} alt={"teleconsultation"} />
      </div>
    : null
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can do like this way also render image conditionally.

condition && <img ... />

Example:

const { forwardRef, useState } = React;

const Parent = () => {
  const [isShowImage, setShowImage] = useState(4);

  const imageShowHandler = () => {
    setShowImage(isShowImage => !isShowImage);
  };

  return (
    <div>
      { isShowImage && <div className={"options"}>
         <img src={'https://image.shutterstock.com/image-photo/silhouette-boy-playing-cricket-evening-600w-1605103354.jpg'} alt={"teleconsultation"} />
      </div>}
      <br />
       <button onClick={imageShowHandler}>Toggle Image</button>
    </div>
  );
};


ReactDOM.render(<Parent />, document.getElementById("root"));
<script crossorigin src="https://unpkg.com/react@17/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@17/umd/react-dom.production.min.js"></script>
<div id="root"></div>

about 4 years ago · Juan Pablo Isaza Denunciar

0

Minimal code

Define a default image in a state and update it based on some condition.

const [defaultImage, setDefaultImage] = useState<image> // your image 

useEffect(() =>{
    if(someCondition) {
        setDefaultImage('newImage');
    }
}, [])


{
    <div className={"options"}>
        <img src={defaultImage} alt={"teleconsultation"}/>
    </div>
}      

This way in future if you intend to display images mulitple times no if/else would be needed at all places. Same code would work too.

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