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

159
Views
What is wrong with my attempt to make React Smooth-Scrolling work?

Im trying to use this package to implement smooth scroll within a Navbar:

https://www.npmjs.com/package/react-scroll

Here's my navbar component:

Navbar.js

import React from "react";
import { Section1, Nav, NavLink, Bars, NavMenu } from "./NavbarElements";
import { Link, animateScroll as scroll } from "react-scroll";

const Navbar = () => {
  return (
    <>
      <Section1>
        <Nav>
          <Bars />
            <Link
              activeClass="active"
              to="section2"
              spy={true}
              smooth={true}
              offset={-70}
              duration={500}
            >
              Home
            </Link>
            <Link
              activeClass="active"
              to="section3"
              spy={true}
              smooth={true}
              offset={-70}
              duration={500}
            >
              Web
            </Link>
            <Link
              activeClass="active"
              to="section4"
              spy={true}
              smooth={true}
              offset={-70}
              duration={500}
            >
              Games
            </Link>
            <Link
              activeClass="active"
              to="section5"
              spy={true}
              smooth={true}
              offset={-70}
              duration={500}
            >
              About
            </Link>
        </Nav>
      </Section1>
    </>
  );
};

export default Navbar;

and here's my App.js

App.js

import React from "react";
import "./App.css";

import Navbar from "./components/navbar";
import HomeSection from "./components/home-section";
import WebSection from "./components/web-section";
import GameSection from "./components/games-section";
import AboutSection from "./components/about-section";

function App() {
  return (
    <>
      <Navbar />
      <HomeSection id="section2" />
      <WebSection id="section3" />
      <GameSection id="section4" />
      <AboutSection id="section5" />
    </>
  );
}

export default App;

What am I missing? I thought I ID'd everything correctly but maybe not? Sorry im a noob. Any glaring issues here I'm missing? Is there a better way to implement one page smooth scrolling with react?

https://imgur.com/PvRRMPL

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

The way react component works that anything you put in the angle bracket its gonna take it as a props here you are not setting up and id you are passing down the prop to your components

<HomeSection id="section2" /> //this is passing props to your homeSection Component

here is how you can fix it:

const HomeSection (props) =>{

return(
<div id={props.id}>  //your parent div

</div>
)

or you can wrap it like that

<div id="id="section2"">
<HomeSection  />
</div>

about 4 years ago · Juan Pablo Isaza Report

0

If anyone ever sees this and needs a solution, you need to wrap <Element> tags around the component like so:

import { Element } from "react-scroll";


const HomeSection = () => {
  return (
    <>
      <Element id="section2" name="home">
        <Section2>
          /* CODE */
        </Section2>
      </Element>
    </>
  );
};

export default HomeSection;
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!