Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@types/react-scroll

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/react-scroll

TypeScript definitions for react-scroll

  • 1.8.5
  • ts4.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
255K
decreased by-0.99%
Maintainers
1
Weekly downloads
 
Created

What is @types/react-scroll?

@types/react-scroll provides TypeScript definitions for the react-scroll library, which is used for smooth scrolling and navigation within a React application.

What are @types/react-scroll's main functionalities?

Smooth Scrolling

This feature allows you to create smooth scrolling links to different sections of your page. The `Link` component is used to create a clickable link that scrolls smoothly to the target `Element`.

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

const SmoothScrollExample = () => (
  <div>
    <Link to="section1" smooth={true} duration={500}>Go to Section 1</Link>
    <Element name="section1">
      <h1>Section 1</h1>
    </Element>
  </div>
);

Scroll Events

This feature allows you to register and handle scroll events. You can use the `Events` object to register callbacks for the beginning and end of a scroll event, and the `scroller` object to programmatically scroll to a specific element.

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

class ScrollEventExample extends React.Component {
  componentDidMount() {
    Events.scrollEvent.register('begin', function() {
      console.log('begin', arguments);
    });

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

  componentWillUnmount() {
    Events.scrollEvent.remove('begin');
    Events.scrollEvent.remove('end');
  }

  scrollTo() {
    scroller.scrollTo('myScrollToElement', {
      duration: 800,
      delay: 0,
      smooth: 'easeInOutQuart'
    });
  }

  render() {
    return (
      <div>
        <button onClick={this.scrollTo}>Scroll to element</button>
        <Element name="myScrollToElement">
          <h1>Scroll to me</h1>
        </Element>
      </div>
    );
  }
}

Scroll Spy

This feature allows you to highlight navigation links based on the current scroll position. The `spy` prop on the `Link` component enables this functionality, and the `scrollSpy` object is used to update the scroll position.

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

class ScrollSpyExample extends React.Component {
  componentDidMount() {
    Events.scrollEvent.register('begin', function() {
      console.log('begin', arguments);
    });

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

    scrollSpy.update();
  }

  componentWillUnmount() {
    Events.scrollEvent.remove('begin');
    Events.scrollEvent.remove('end');
  }

  render() {
    return (
      <div>
        <Link to="section1" spy={true} smooth={true} duration={500}>Section 1</Link>
        <Link to="section2" spy={true} smooth={true} duration={500}>Section 2</Link>
        <Element name="section1">
          <h1>Section 1</h1>
        </Element>
        <Element name="section2">
          <h1>Section 2</h1>
        </Element>
      </div>
    );
  }
}

Other packages similar to @types/react-scroll

FAQs

Package last updated on 14 Nov 2022

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc