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

199
Visualizações
No items being rendered when the page reloads - trying to implement a search bar

I am trying to implement a search bar and I am going to attach the code for it below. The issue is that when the page reloads and the search bar is empty, no products end up getting render but as soon I start typing something in the search bar, the items start to render as per the search key.

Can anyone assist me with this please?

          .filter((val) => {
            if (props.searchTerm == "") {
              return val;
            } else if (
              val.additionalInfo.toLowerCase().includes(props.searchTerm)
            ) {
              return val;
            }
          })
          .map((post) => {
            return (
              <div className="product-metainfo col-2 mb-4">
                <img src={post.images[0].src}></img>
                <h3 className="product-brand">{post.brand}</h3>
                <h4 className="product-product">{post.additionalInfo}</h4>
                <div className="product-price">
                  <span>
                    <span className="discounted-price">Rs. {post.price} </span>
                    <span className="product-strike"> Rs. {post.mrp}</span>
                  </span>
                  <span className="product-discountPercentage">
                    ({Math.floor((100 * post.discount) / post.mrp)}% off)
                  </span>
                </div>
              </div>
            );
          })}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Did you set the default state for searchTerm as undefined or null? In this case you need to set the default state for searchTerm as empty string to make it work.

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