@ganeshdole/scrolltotop
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

@ganeshdole/scrolltotop

Description

In a React Single Page Application (SPA), users often expect the view to scroll to the top when they navigate to a new page. Without this functionality, users might find themselves starting at an arbitrary scroll position, which can be confusing and lead to a poor user experience. The @ganeshdole/scrolltotop package provides a simple solution to this problem by automatically scrolling the window to the top whenever a new page is loaded using React Router.

Features

  • Automatically scrolls the window to the top when a new page is loaded.
  • Compatible with React Router.

Installation

To install the package, use npm:

npm install @ganeshdole/scrolltotop

Usage

  1. Import the ScrollToTop component from @ganeshdole/scrolltotop.
  2. Wrap the ScrollToTop component around the content of your application.
  3. Ensure React Router is set up in your project if you're using it.

Example:

import ReactDOM from "react-dom/client";
import App from "./App.tsx";
import "./index.css";
import { BrowserRouter } from "react-router-dom";
import ScrollToTop from "@ganeshdole/scrolltotop";

ReactDOM.createRoot(document.getElementById("root")!).render(
  <BrowserRouter>
    <ScrollToTop>
      <App />
    </ScrollToTop>
  </BrowserRouter>
);

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

Readme

Keywords

Package Sidebar

Install

npm i @ganeshdole/scrolltotop

Weekly Downloads

0

Version

1.0.4

License

MIT

Unpacked Size

3.75 kB

Total Files

5

Last publish

Collaborators

  • ganeshdole