Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

173
Views
Reaccionar: ¿Cómo generar un respaldo para un componente de TypeAhead cuando la búsqueda no produce ninguna coincidencia?

Estoy trabajando en un componente Typeahead en reaccionar.

Actualmente, solo estoy filtrando los datos a través de una entrada de texto y luego mapeándolos para mostrar las opciones filtradas en el DOM. Eso está llegando, pero me gustaría mostrar "No se encontraron elementos" si la búsqueda no arroja nada.

Así es como devuelvo los artículos <li></li> :

 <ul className="search-container__dropdown" onClick={(e) => e.stopPropagation()} style={{ display: show ? 'block' : 'none' }}> {comments.length > 0 ? comments .filter(({ body, name }) => { if (!input) return true; if (body.includes(input) || name.includes(input)) { return true; } return false }) .map(({ id, name, body, notfound }, index, arr) => { return ( <li onClick={() => handleClick(id)} className={`search-container__option ${id === cur_section ? "active" : ""}`} key={id} value={name}> <strong>name: </strong>{name},<br /> <strong>body: </strong>{body} </li> ) }) : <NothingFound />} </ul>

Este es el componente NothingFound:

 function NothingFound() { return <li>Nothing found</li> }

¿Qué me estoy perdiendo?

¡Gracias por adelantado!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Primero debe filtrar y luego verificar la longitud de los comentarios filtrados de la siguiente manera:

 const filteredComments = comments .filter(({ body, name }) => { if (!input) return true; if (body.includes(input) || name.includes(input)) { return true; } return false; }) return (<main> ... {filteredComments.length > 0 ? ( filteredComments .map(({ id, name, body, notfound }, index, arr) => { return ( <li ...
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!