¿Cómo puedo implementar estos dos filtros con postRes en la fila de la tabla? postRes es la respuesta json api. includeKeyword & searchVolume es gancho de estado. no quiero implementar filtros si los estados están vacíos. Agradezco tu ayuda de antemano
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) )Devolver
<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> }Cree una función de filtro con sus diversos criterios y pásela al prototipo Array.filter. La función se verá así (no probada):
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) } }y pásalo antes de tu mapa:
includeKeywordResults.filter(filterFunction).map((data, index) => (