Reactjs filter where result is zero

I want to have text on the page change when no items from a mapped array are showing.
I am showing a list of questions, but if a question is "answered" (a boolean of answered: true), it is not mapped.

I’m trying to figure out the best way to determine if every item in the array has answered: true, and then change text on the page accordingly. Is it possible to use filter for this when I need a function that checks for no results coming back?

The page shows a list to the left, and the text "please click on a question" to the right. When a question is selected, it replaces "please click on a question" with information about the selected question. But when there are no questions, I want "please click on a question" to show something like "There are currently no questions to answer".

this.state = {
      questions: [],
      currentQuestion: null,
      currentIndex: -1,
      searchQuestion: "",
      wanttodelete: false
};

{questions &&
              questions.map((question, index) => (
                <div key={index}>
                  {!question.answered &&
                <li
                  className={
                    "list-group-item " +
                    (index === currentIndex ? "active" : "")
                  }
                  onClick={() => this.setActiveQuestion(question, index)}
                  key={index}
                >
                  <p>
                  {question.question}
                  </p> 
                </li>
                }
                </div>
))}
</ul>
        </div>
        <div className="col-lg-8 question-area">
          {currentQuestion ? (
            <div>
              <h4>
              <FormattedMessage 
                id="question-list.questionHeader"
                defaultMessage="Question"
                description="Question header"/>
              </h4>
              <div>
                <label>
                  <strong>Question:</strong>
                </label>{" "}
                {currentQuestion.question}
              </div>
              <div>
                <label>
                  <strong>Category:</strong>
                </label>{" "}
                {currentQuestion.categoryId}
              </div>
              <div>
                <label>
                  <strong>Status:</strong>
                </label>{" "}
                {currentQuestion.answered ? "Answered" : "Awaiting answer"}
              </div>

              <Link
                to={"/questions/" + currentQuestion.id}
                className="badge badge-warning"
              >
                Answer this question
              </Link>
            </div>
          ) : (
            <div>
              <p>Please click on a Question...</p>
            </div>
          )}
        </div>
        </div>
      </div>
      </div>
    );
  }
}

163 thoughts on “Reactjs filter where result is zero”

  1. Pingback: debviagrals.com
  2. Pingback: viagra prices
  3. Pingback: viagra sale
  4. Pingback: sex pills cialis
  5. Pingback: viagra pills
  6. Pingback: cialis canada
  7. Pingback: sildenafil nz
  8. Pingback: viagra gel caps
  9. Pingback: cialis 10 mg
  10. Pingback: walgreens cialis
  11. Pingback: viagra walmart
  12. Pingback: viagra men
  13. Pingback: viagra dosage
  14. Pingback: viagra ohne rezept
  15. Pingback: viagra jokes
  16. Pingback: viagra online
  17. Pingback: viagra price
  18. Pingback: cheap viagra
  19. Pingback: walmart viagra
  20. Pingback: viagra sildenafil

Leave a Comment