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

132
Vistas
persons.filter is not a function

so I am trying to make a filter search. I am calling the function using


      <h2>Numbers</h2>
      {
        persons.map((persons) => <Persons persons={persons} setFilter= {setFilter} key={persons.id} />)
      }
    </div>

so I created an array using map however when I pass it through

  const Persons = ({ persons, setFilter }) => {
    const checkPersonsName = setFilter === '' ? 
      persons
    :
      persons.filter((person) => person.name.toLowerCase().includes(setFilter) )
    return (<li>{checkPersonsName.name} {checkPersonsName.number}</li>)

  }
  

it gives me an error saying:

Uncaught TypeError: persons.filter is not a function.

I did a console.log and persons should be an array. so I am not quite sure what to do here and why I am getting this error.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

As far as I concern, you are using persons two times unnecessarily. You first map throught the array persons and then use the same persons as a prop of the component Persons.

I think that it'd be better if you use Persons as a function, not as a React component, and insert your map and li rendering after the filter. Check my codesandbox here

about 4 years ago · Juan Pablo Isaza Denunciar
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