Skip to content

How to reset the search results without using state? #807

Answered by F-Kirchhoff
kabaskill asked this question in Web
Discussion options

You must be logged in to vote

Hello Oguz,
your "results" array depends on the filters State. So when the filters are reset to default, your results will be recalculated automatically. The only issue that could arise is, that your filtering is not set up correctly. If the filters are empty you generally want to include all elements from the array, but when you check for example if the name includes the string "" then no game will pass. Therefore, you need to check first if the filters are empty and if so don't filter at all!

function filterGames(games) {
  const filteredForName = filters.name === "" ? games : games.filter(game => game.startsWith(filters.name))
  const filteredForCategories = filters.categories ===  '' ? 

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by kabaskill
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Web
Labels
None yet
2 participants