mercredi 19 février 2020

Delete element from a list, with multiple lists to check -- what's a good way to implement?

I created state within App.js for a single page application (kanban board)

Within the state i have three key values with arrays and one other key value:

    this.state = {
      currentItem: { text: '' },
      toDoListItems: [
        { text: 'hello world' }
      ],
      inProgressListItems: [],
      doneListItems: []
    }

Currently my implementation of use cases like delete a task from any board, is implemented by passing the name of the list item.

ie. {() => this.deleteItem(item, "toDoListItems")}

How should i make my code more extensible? I was thinking first, I should place all the lists within an object within state. But is it good/bad practice to manually iterate and which array contains the element that I'm looking for? It feels like if i were to do that, I'm making redundant checks.

Aucun commentaire:

Enregistrer un commentaire