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

291
Vistas
React Auto Scroll to show Fetched Data

Im new to react and im trying to auto scroll to Section where data will be shown after being fetched

scrolling should be after data is fetched

const  App = () => {
const [Data ,setData] = useState([])
const [InputTracking , setInputTracking] = useState('')
const [isLoading,setIsLoading] = useState(false)
const [Clicked , setClicked] = useState(false)
//button onClick function 
const searchTrackingID = async (TrackingID) => {
     console.log(TrackingID)
      setIsLoading(true);
      const response = await axios(API_URL+TrackingID) ;
      const res = await response.data ; 
      setData(res)
      setIsLoading(false);
      setClicked(true);
  }
}
 return (
<Header />
//here a form with a text input and button (after clicking it , wait for Data to change state then AUTO SCROLL TO Data (section)
 <section >
  <div >
    <div >
{
   Data.slice(1).reverse().map((mydata)=>(
   <TrackingInfo  Maindata={mydata}/>
   ))
} 
  </div>
  </div>
</section> 
) 
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

function TestComponent() {
   const testRef = useRef(null);
   const scrollToElement = () => testRef.current.scrollIntoView();
  useEffect(()=>{
  if(loading){
    scrollToElement()
  }
  }, [loading])
 

  // Once the scrollToElement function is run, the scroll will show the element
  return (
    <>
      <div ref={testRef}>Element you want to view</div>
    </>
  );
}

Reference : https://www.delftstack.com/howto/react/scroll-to-an-element-in-react/

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