mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-24 20:36:40 +07:00
refactored hooks directory
This commit is contained in:
parent
efa3ba902d
commit
f76a5a4798
106 changed files with 122 additions and 144 deletions
|
@ -1,19 +0,0 @@
|
|||
import { useEffect } from 'react';
|
||||
import { NEW_COMMENT_CLASSNAME } from '~/constants/comment';
|
||||
|
||||
export const useScrollToTop = (deps?: any[]) => {
|
||||
useEffect(() => {
|
||||
const targetElement = document.querySelector(`.${NEW_COMMENT_CLASSNAME}`);
|
||||
|
||||
if (!targetElement) {
|
||||
window.scrollTo(0, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
const bounds = targetElement.getBoundingClientRect();
|
||||
window.scrollTo({
|
||||
top: bounds.top - 100,
|
||||
behavior: 'smooth',
|
||||
});
|
||||
}, deps || []);
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue