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

143
Vistas
Scroll to an element when clicking a button

I want to scroll to a div element when I click a button. But unfortunately the scroll isn't working. But my console.log()

I read this Scroll to the top of the page after render in react.js and this How to scroll to an element?

import React, { useEffect, useState, useRef } from 'react'

function TeamOld() {
    const myRef = useRef(null)

    return (
        <div>
                <button class="button is-primary is-outlined mr-4 mb-2" onClick={() => {myRef.current.scrollTo(0, 0); console.log("Test")}}>Click me</button>
            ...
            <div className="" style={{ width: "100%" }} ref={myRef}>
            </div>
        </div>
    )
}
export default TeamOld
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The function you are looking for is scrollIntoView (https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView) scrollTo is used to scroll the element itself (assuming you have scrollbars inside your div).

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