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

283
Vistas
Getting .startsWith() is not a function in react native

I want to search items through a search bar.The original items are in prod.but I keep getting startsWith() not a function and sometime .toLowerCase() is not a function

const [prod, setprod] = React.useState([]);
const [getFiltered, setFiltered] = React.useState([]);
const [getSearch,setSearch]=React.useState("");


const SearchItem=(text)=>{
  if(text!=""){
    const searched=prod.filter((item)=>{
      const datachange=item.toLowerCase();
      const textchange= text.toLowerCase();
      return datachange.startsWith(textchange);
    });
    setFiltered(searched);
    setSearch(text)
  }
  else{
    setFiltered(prod);
    setSearch(text);
  }}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I agree with @lucasvw that more information would be helpful here.

However, your conditional is only validating that text!="", but if text is something else, like a number, function, or (more likely) undefined or null, this will throw.

I'd recommend changing to something like this:

if (typeof text === "string" && text != "") {
# the rest of your code
}

EDIT:

Sorry, it's actually item that's throwing.

Same idea, but try this instead:

    const searched=prod.filter((item)=>{
      if (typeof item !== "string") {
        return false;
      }
      const datachange=item.toLowerCase();
      const textchange= text.toLowerCase();
      return datachange.startsWith(textchange);
    });
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