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

196
Views
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 4 years ago · Juan Pablo Isaza
2 answers
Answer question

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 4 years ago · Juan Pablo Isaza Report

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 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!