Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

223
Visualizações
How can I use ScrollTo in React Native?

I'm quite new to React Native, I'm developing an app for advertising where there are categories and adverts listings. I would like to have the animation when the user clicks on a category, the screen should scroll downwards to the section with "Latest Ads". I'm not using ScrollView, I have used two Flatlists one for the categories and the other for products/adverts.

I have tried to use scrollTo() as shown in react native documentation (https://reactnative.dev/docs/scrollview#scrollto) Please help.

Below is part of my code in my JSX file that gives me an error:

//Scroller code starts
  const myScroller = () => {
    scrollTo({ x: 0, y: 90, animated: true });
  };
  // Scroller code ends
  const handleSelectCategory = (item) => {
    setSearchData((prevSearchData) => {
      return { ...prevSearchData, categories: item.term_id, page: 1 };
    });
    dispatch({
      type: "SET_CAT_NAME",
      cat_name: [item.name],
    });
    setLoading(true);
    myScroller();   
  };

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You need to use ref to scroll

import { useRef } from 'react';
...

...
const scrollRef = useRef(null); // inside your function component
...

const myScroller = () => {
    scrollRef ?.current ?.scrollTo({ x: 0, y: 90, animated: true });
};

...
<FlatList
  ref={scrollRef} // put reference in FlatList which need to scroll
...
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda