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

224
Views
Reaccionar crear más/cerrar al hacer clic en el botón Escriba Error

Hice una función que imprime 5 datos a la vez e imprime toda la longitud de datos cuando se presiona el botón Más.

Pero hay un problema. Cada vez que hago clic en el botón me sale un error.

Para ilustrar mi código, primero creo un estado visible y solo muestro 5 al principio. 'expandido' dice 'verdadero todas las llamadas de productos' cuando se hace clic en un 'botón' 'falso muestra solo los primeros 5'

 const [visible, setVisible] = useState(5) const [expanded, setexpanded ] = useState(false); const showMore = () => { visible === 5 ? ( setVisible(ProductDetail.allergies.length) ) ( setexpanded(true) ) : ( setVisible(5) ) ( setexpanded(false) ) return ( {ProductDetail && ProductDetail.allergies?.length ? ProductDetail.allergies.slice(0, visible).map(All => ( <li key={All.id}> {All.displayText}</li> )) : <li>No information.</li>} ) <button type="button" onClick={showMore}> {expanded ? ( <span>close</span> ) : ( <span>see more</span> )} </button> }

Pero cada vez que hago clic en el botón me sale un error.

TypeError: setVisible(...) no es una función

 46 | 47 | 48 | const showMore = () => { > 49 | visible === 5 ? ( 50 | setVisible(ProductDetail.allergies.length) 51 | ) ( 52 | setexpanded(true)

no se como solucionarlo ¿Cómo le gustaría modificar el código? Ah, y quiero que los botones sean invisibles si hay menos de 5 al principio, pero no sé cómo escribir el código.

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