🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

react-scroll

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
r

react-scroll

A scroll component for React.js

1.9.3
latest
100

Supply Chain Security

100

Vulnerability

100

Quality

78

Maintenance

100

License

Version published
Weekly downloads
503K
7.81%
Maintainers
0
Weekly downloads
 
Created
Issues
231

What is react-scroll?

The react-scroll package provides smooth scrolling functionality for React applications. It allows developers to create scrollable components and implement smooth scrolling animations to specific elements within a page.

What are react-scroll's main functionalities?

Smooth Scrolling to Elements

This feature allows you to create links that smoothly scroll to specific elements on the page. The 'Link' component is used to create the scrollable link, and the 'Element' component is used to define the target section.

import { Link, Element } from 'react-scroll';

function App() {
  return (
    <div>
      <Link to="section1" smooth={true} duration={500}>Go to Section 1</Link>
      <Element name="section1" className="element">
        Section 1
      </Element>
    </div>
  );
}

Scroll Events

This feature allows you to register and handle scroll events. You can log or perform actions when scrolling begins or ends. The 'animateScroll' function can be used to programmatically scroll to specific positions.

import { Events, animateScroll as scroll, scroller } from 'react-scroll';

function App() {
  useEffect(() => {
    Events.scrollEvent.register('begin', function() {
      console.log('begin', arguments);
    });

    Events.scrollEvent.register('end', function() {
      console.log('end', arguments);
    });

    return () => {
      Events.scrollEvent.remove('begin');
      Events.scrollEvent.remove('end');
    };
  }, []);

  return (
    <div>
      <button onClick={() => scroll.scrollToTop()}>Scroll to Top</button>
    </div>
  );
}

Scroll to Top

This feature provides a simple way to scroll to the top of the page programmatically. The 'scrollToTop' function from 'animateScroll' is used to achieve this.

import { animateScroll as scroll } from 'react-scroll';

function App() {
  return (
    <div>
      <button onClick={() => scroll.scrollToTop()}>Scroll to Top</button>
    </div>
  );
}

Other packages similar to react-scroll

FAQs

Package last updated on 19 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts