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

416
Visualizações
How to use scrollintoview inside useeffect ( Cannot read properties of null (reading 'scrollIntoView') )

I need to set my webPage from beginning to start. So I write code like this.

function BasicDetails() {

    React.useEffect(()=>{
        scrollView();
    }, []);

    function scrollView() {
        document.getElementById('main-root').scrollIntoView({behavior: 'smooth'});
    }
    return (
        <Nav>
            <div id="main-root" style={{scrollBehavior: 'smooth'}}>
                <div>
                    <Header pageTitle={'Shop Settings'}/>
                    <Button
                        onClick={saveBasicDetails}
                        variant="contained"
                        id='save'
                        className={classes.saveButton}>
                        SAVE
                    </Button>
                </div>

                <BasicDetailsData style={{scrollBehavior: 'smooth'}} ref={childRef}/>
            </div>
        </Nav>
    );
}

But When I Tried to run my code, I have an error TypeError: Cannot read properties of null (reading 'scrollIntoView') So I tried many times but can't find the error. I am a new student for react, so. I don't know much about it. Anyone can help me with this...I really need your help..thank you.

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

0

I tried this out and this is how I got it to work:

function scrollView() {
    const mainRoot = document.getElementById("main-root");
    mainRoot.scrollIntoView({ behavior: "smooth" });
  }

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