react-scroll-id

1.0.8 • Public • Published

react-scroll-id

This package is a used to scroll up and down to the exact component in the application

NPM JavaScript Style Guide

Install

npm install --save react-scroll-id

Example

LINK - Codesandbox

Usage

Function Component

import React from 'react'
import SectionScrollable ,{ScrollTo} from 'react-scroll-id'
const App = () =>{
  return (
    <SectionScrollable>
      <button onClick={()=>{ScrollTo({targetId:'exampleId',behavior:'auto'})}}>Click Me</button>
      <div id={'exampleId'}></div>
    </SectionScrollable>
  )
}

Class Component

import React, { Component } from 'react'
import SectionScrollable ,{ScrollTo} from 'react-scroll-id'
class Example extends Component {
  render() {
     return (
    <SectionScrollable>
      <button onClick={()=>{ScrollTo({targetId:'exampleId'})}}>Move to Container 1</button>
      <button onClick={()=>{ScrollTo({targetId:'containerId'})}}>Move Away</button>
      <div id={'exampleId'}>Container 1</div>
       <div id={'containerId'}>Away from the container</div>
    </SectionScrollable>
  )
  }
}

License

MIT © [Yaswanth L](https://github.com/Yaswanth L)

Package Sidebar

Install

npm i react-scroll-id

Weekly Downloads

0

Version

1.0.8

License

MIT

Unpacked Size

7.26 kB

Total Files

7

Last publish

Collaborators

  • dlyaswanth