Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

163
Visualizações
JavaScript / React Can't Filter An Array By Attributes

I'm currently trying to develop a filtering system for a React e-commerce store. I have a list of products in an array, however when trying to filter by the filters requested, I get errors that: Uncaught TypeError: Cannot read properties of undefined (reading 'includes').

This is the product schema:

const ProductSchema = new mongoose.Schema({
    title: {type: String, required: true, unique: true},
    description: {type: String, required: true, unique: true},
    image: {type: String, required: true},
    categories: {type: Array},
    sizes: {type: Array},
    color: {type: Array},
    price: {type: Number, required: true}

}, {timestamps: true});

This is the line of code where I'm trying to set filteredProducts to then map over each and display them:

useEffect(() => {
    // category &&
      setFilteredProducts(
        products.filter((item) =>
          Object.entries(filters).every(([key, value]) =>
            item[key].includes(value)
          )
        )
      );

  }, [products, category, filters]);

I think what it is saying is that 'colors' and 'sizes' are not attributes of the product. For reference, this is the filters object that is passed through: {colors: 'black', sizes: 's'}.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda