• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

153
Vistas
How to make a message appear once email is submitted using React and CSS

I am using React and have built an email form. I currently have this class: <div className="msg">Message has been sent</div> but only want it to appear when the message has successfully sent. So only when the following resolves as status: true. How can I target this using only React/CSS?

  .post('/api/email', values)
  .then((res) => {
    console.log("Server responded")
    setValues({
      name: "",
      email: "",
      message: "",
      status: true
    })
    .catch(err => {
      console.log(err);
      window.alert("Email not sent")
    });```


about 3 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

if your status varible named status then

<div className="msg" style={{display: status ? "block" : "none"}}>Message has been sent</div>

That's it.

And I suggest that you should add following code.

.catch(err => {
setValues({
  name: "",
  email: "",
  message: "",
  status: false
  })
  console.log(err);
  window.alert("Email not sent")
});```
about 3 years ago · Juan Pablo Isaza Denunciar

0

Wrapping the div between curly brackets, and add a condition && should do the work:

{values.status && <div className="msg">Message has been sent</div>}
about 3 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 Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda