Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

148
Vistas
How to create an interactively filter input in react

I'm learning react and trying to build an triomphe card game,

In this game i have a section where i can create the deck of cards and a section where i can filter a card by name.

i'm triyng to make a interactively filter input that onchange calls a handleFilter function that get the value of the input and create a new array of filtered items.

First i use filter array method to filter the array of all cards and then i check if the name of cards includes the value from input.

Here's my function handleFilter:

    handleFilter({ target: { value } }) {
        const { cards } = this.state;

    this.setState({ cardFilter: value });

    const filterByName = cards.filter(({ cardName }) => (
      cardName.toLowerCase().includes(value.toLowerCase())));

    if (filterByName.length > 0) {
      this.setState({ filter: filterByName,
        found: true,
      });
    }
  }

I have a problem when my input not match with the name of any card in deck, in that situation i wish that no card is showed.

Instead, lets assume i have a card named pikachu and i search for pikaboo.

I still get pikachu in my array as both includes 'pika' and when i do the filter and includes name it will get true and add pikachu to the filtered list that will be rendered afterwards.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda