0

I am practicing with React and sorting lists. Now I have an array with object, a value of an object is' isDeleted 'by default it is 0, if the user deletes the item this is 1. All values are' mapped 'in a list, it is possible to change the objects with' isDeleted === 1 'from this list. currently this is my code for rendering the list:

      {
        this.state.questions.sort(function(a, b) { return a.isDeleted-b.isDeleted;}).map((question, i) => (
            <li key={i}><span className="question-list">{question.vraag}</span>  <span className="see-list-delete"><a onClick={() => this.deleteQuestion(question.key,i)}><i class="far fa-trash-alt"></i></a></span> <span className="see-list-edit"><a href="#"><i class="far fa-edit"></i></a></span></li>
        ))
      }

An object in the array has the following structure:

{id: state.id, setname: state.setname, categoryName: state.categoryName, vraag: state.vraag, key: state.key, isDeleted: state.isDeleted}

So if isDeleted 1is it should not be visible in the map

1

1 Answer 1

1

You can just filter it:

this.state.questions.filter( x => !x.isDeleted).sort....

You can read more about filter here

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much for the quick response! This has helped enormously

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.