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

125
Vistas
How to implement / render two filters separately using react

How can i implement these two filter with postRes in table row ? postRes is json api response. includeKeyword & searchVolume is State hook. i don't want to implement filters if states are empty. i appreciate your help in advance

  let includeKeywordResults = !includeKeyword  ? postRes : postRes.filter(data =>
    data.text.toLowerCase().includes(includeKeyword.toLocaleLowerCase())) 
  

 let searchVolumeResults = !searchVolume ? postRes : postRes.filter(data => 
  data.keyword_idea_metrics.avg_monthly_searches > parseInt(searchVolume) )

Return

        <div className="container table-responsive py-5"> 
      <table className="table table-bordered table-hover" id="table-to-xls">
        <thead className="text-white bg-dark">
          <tr>
            <th scope="col">Keyword</th>
            <th scope="col">Search Volume</th>
            <th scope="col">Competition</th>
            <th scope="col">CPC</th>
          </tr>
        </thead>
        <tbody>
    {includeKeywordResults !== undefined ? includeKeywordResults.map((data, index) => (
          <tr key={index}>
            <td>{data.text}</td>
            <td>{data.keyword_idea_metrics.avg_monthly_searches}</td>
            <td>{data.keyword_idea_metrics.competition}</td>
            <td>{data.keyword_idea_metrics.low_top_of_page_bid_micros}</td>
          </tr>
  )) : null}
  
  </tbody>
      </table>
      </div>
      </div>
    }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Create a filter function with your various criteria and pass it to the Array.filter prototype. Function will look like something like that (not tested):

const filterFunction = (a) => {
   if (!includeKeyword && !searchVolume){
      return true
   } else if (includeKeyword && !searchVolume){
      return a.text.toLowerCase().includes(includeKeyword.toLocaleLowerCase())) 
   } else if (!includeKeyword && searchVolume){
      return  a.keyword_idea_metrics.avg_monthly_searches > parseInt(searchVolume)
   } else {
      a.text.toLowerCase().includes(includeKeyword.toLocaleLowerCase())) && a.keyword_idea_metrics.avg_monthly_searches > parseInt(searchVolume) 
   }
}

and pass it before your map:

includeKeywordResults.filter(filterFunction).map((data, index) => (
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