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

162
Vistas
react More Collapse and Expand

At first, I want to make only 5 data.text values ​​visible and all data.text to be exposed when the More button is clicked. Then I want to only 5 data.text visible when the close button is pressed.

However, in the code I wrote, at first, five are visible, but when the More button is clicked, it doesn't work properly.

How do I modify the code to make it work?

   const [visible, setVisible] = useState(5)
   const [expanded, setexpanded ] = useState(false);

      const showMore = () => {
        visible === 5 ? (
            setVisible({ visible: ProductDetail.allergies.length, expanded: true })
         
        ) : (
            setVisible({ visible: 5, expanded: false })
        )
    }

  return (
     
     <ul>
         {ProductDetail && ProductDetail.allergies?.length ? 
                            ProductDetail.allergies.slice(0, 
                           visibleBlogs).map(All => (
                            <li key={All.id}>
                             .....
                             </li>
    </ul>

                    <button type="button" onClick={showMore}>
                        {expanded ? (
                            <span>close</span>
                        ) : (
                            <span>more</span>
                        )}  
                    </button>
                    

                    
)

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