Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Render JSX element only when another element is null

I have a page, the structure looks like this:

export default function MyBidPage() {
  return (
    <div className="children:mb-4">
      <AskToQualifyForm />
      <CreateBidSection />
      <DocumentsSection />
      <AboutBidderSection />
      <ExclusionGroundsSection />
      <SelectionCriteriaSection />
    </div>
  );
}

I want to hide <CreateBidSection /> only when <AskToQualifyForm /> is present in the page. How could I do that?

I was thinking about something like this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

{! <AskToQualifyForm /> && <CreateBidSection />}

but sadly it’s not a valid code 🙁

P.S. A method without using state would be highly appreciated

>Solution :

Further to T.J. Crowder’s comment above,

export default function MyBidPage({...props}) {
  const { canAskToQualify = false } = props || {};
  return (
    <div className="children:mb-4">
      {canAskToQualify && <AskToQualifyForm />}
      {!canAskToQualify && <CreateBidSection />}
      <DocumentsSection />
      <AboutBidderSection />
      <ExclusionGroundsSection />
      <SelectionCriteriaSection />
    </div>
  );
}

If one is able to send the flag as a prop into the method, then it may be used to conditionally display the two components.

NOTE: This may be one possible way to achieve the desired result.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading