Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

407
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!