Skip to main content

usePreventBrowserScrollRestoration

A hook that prevents the browser's default scroll restoration behavior.

When the component mounts, it sets window.history.scrollRestoration to 'manual' to disable the browser's automatic scroll restoration. When the component unmounts, the original value is restored.

This hook is used when implementing custom scroll restoration logic to prevent conflicts with the browser's default behavior.


Code

🔗 View source code


Interface

typescript
const usePreventBrowserScrollRestoration: () => void;

Usage

typescript
import { usePreventBrowserScrollRestoration } from '@modern-kit/react';

const MyComponent = () => {
usePreventBrowserScrollRestoration();

return <div>window.history.scrollRestoration: {window.history.scrollRestoration}</div>;
};

Example