3.1.7 • Published 1 year ago

react-use-scroll-navigate v3.1.7

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

React use scroll navigate

This is a react hook that allows you to navigate to a specific section of a page by scrolling to it.

Demo

Visit demo page

Installation

npm install react-use-scroll-navigate

Usage

useScrollNavigate

import useScrollNavigate from 'react-use-scroll-navigate';

const App = () => {

    const { scrollNavigateError, scrollNavigate } = useScrollNavigate();
  
  return (
    <div>
        <button onClick={ ()=> { 
            scrollNavigate('/'); //It will navigate & scroll to the top ! 
        }}>
            Go to homepage!
        </button> 
    </div>
  );
};

NavigationRef

//Main app 

createRoot(document.getElementById("root")).render(
    <StrictMode>
        <BrowserRouter>
            <NavigateContextProvider> {/*Ref navigation scroll navigation works with context*/}
                <App /> {/*here is the rooter */}
            </NavigateContextProvider>
        </BrowserRouter>
    </StrictMode>
)
//On one page

export default () => {
    const { navigateToRef } = useNavigateContext();

    return (
        <Fragment>
            <h1>About</h1>
            <button onClick={() => navigateToRef("/")}>Home</button>
        </Fragment>
    )
}
// On another page
export default () => {
    const { navigationRef } = useNavigateContext();

    return (
        <Fragment>
            <h1>Home</h1>
            <div ref={navigationRef} />
        </Fragment>
    )
}

License

MIT

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Authors and acknowledgment

3.1.7

1 year ago

6.0.2

2 years ago

6.0.1

2 years ago

6.0.0

2 years ago

5.0.1

2 years ago

5.0.0

2 years ago

4.0.3

2 years ago

4.0.2

2 years ago

4.0.1

2 years ago

4.0.0

2 years ago

3.1.6

2 years ago

3.1.5

2 years ago

3.1.4

2 years ago

3.1.3

2 years ago

3.1.2

2 years ago

3.1.1

2 years ago

3.1.0

2 years ago

3.0.0

2 years ago

2.1.0

2 years ago