How to get the array object from a specific history.location.pathname

131 Views Asked by At

My issue is that when i call the function getAllFlashCardsFromQuest(), its call all flash cards ever created in all the pages, i wanna only the objects that comes from a specific pathname, or a way to filter the cards array.

async function getCards() {
    let cardsValues = await getAllFlashCardsFromQuest() as FlashCard[]
    let cardsFiltered = cardsValues.filter(()=>{
        return history.location.pathname === 'CriarAlternativaQuest'
    })
    console.log(cardsFiltered)
    setCards(cardsFiltered)
}

the object look like this: enter image description here

1

There are 1 best solutions below

1
On

There's not much context with your code, so I can only help so much, but one thing's for sure, and that is history.location.pathname isn't changing and you're comparing it with another constant. So cardsFiltered will be either a list of true or a list of false.

Whenever you're filtering a list, you need to take each item or a property of each item and use that in your comparison.

Ex.

async function getCards() {
    let cardsValues = await getAllFlashCardsFromQuest() as FlashCard[]
    let cardsFiltered = cardsValues.filter((cardValueItem) => {
        return cardValueItem.pathname === 'CriarAlternativaQuest'
    })
}

The thing is that you need to figure out what value or property inside of your cardsValues list that you need to compare it with 'CriarAlternativaQuest'