简体   繁体   中英

Alternative to nested ternary operator?

{isPage ? (
      hasHtml? (
        <iframe
          src="about:blank"
          title="pages"
          frameBorder="0"
          scrolling="no"
        />
      ) : (
        <p>This page has no html</p>
      )
    ) : (
      <iframe
        src="about:blank"
        title="pages"
        frameBorder="0"
        scrolling="no"
      />
    )}

This code block has nested ternary operator? Is there any alternatives for this so that i dont have to repeat the iframe code block portion twice? That portion seems redundant. Thanks

As suggested in one of the comments:

   {isPage && !hasHtml? (
      <p>This page has no html</p>
    ) : (
      <iframe
        src="about:blank"
        title="pages"
        frameBorder="0"
        scrolling="no"
      />
    )}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM