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

169
Views
How activate and deactivate a independent react component?

I codded an Alert component. That I can show info, success, error and warning. I need to make this component completely independent. But there are some problems. I don't want to use state in Alert's parent - because it makes Alert more non-independent

I close alert by removing Alert's elements but this caused Alert does not show anymore ( When user make mistake for second times)

Do you have any idea to solve this problem??

Alert's parent:

  return (
<main>
  <div className="welcome-panel flex-column">
    {todoState.added ? (
      <>
        <Alert severity="error" style={{ marginBottom: "1rem" }}>
          Field should not be empty
        </Alert>
        <Alert severity="info" style={{ marginBottom: "1rem" }}>
          Field should not be empty
        </Alert>
      </>
    ) : null}
    {welcomePanel}
  </div>

  <div className="todos flex-row">{todos}</div>
</main>

);

Alert component:

 return (
    <div className={`${severity} alert flex-row alert-component`} style={style}>
      <section className="alert-body flex-row">
        <div className="close">
          <section>
            <span></span>
            <span></span>
          </section>
          <div onClick={closeAlert}></div>
        </div>
        <div className="alert-severity-icon ">{severityIcon.get(severity)}</div>
        <div className="alert-information">
          <div className="title">
            <strong>
              {severity.replace(
                severity.charAt(0),
                severity.charAt(0).toUpperCase()
              )}
            </strong>
          </div>
          <div className="body">
            <p>
              {children}
              <strong> - check it out</strong>
            </p>
          </div>
        </div>
      </section>
    </div>
  );

Close alert:

function closeAlert(event) {
    event.nativeEvent.path[3].remove();
  }
about 4 years ago · Juan Pablo Isaza
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!