0

I am trying to implement an else part when there are no references, and display no data is available , but i am currently using reactjs with typescript , how do I implement this check?

<div className="overview-text">
<div className="overview-text-header">References</div>
{data.reference.map((reference) => (
    <div className="overview-text-item" key={reference}>{urlParser(reference)}</div> // if there is no data then no data available
))}
</div>
4
  • {data?.reference ? data.reference.map(...) : <span>No data</span>} Commented Mar 12, 2021 at 4:49
  • What did you try and what happened? Did you get an error? Commented Mar 12, 2021 at 4:50
  • Does this answer your question? ternary operator in jsx to include html with react Commented Mar 12, 2021 at 4:51
  • You know official documentation exists, right? Commented Mar 12, 2021 at 5:22

1 Answer 1

0

This should do it:

<div>
  { 
    data.reference && data.reference.length ?
     (if part)
     : (else part)
  }
</div>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.