react-hooks
useVisibleElement
usage
import { useVisibleElement } from '@lani.ground/react-hooks';
export default function Component() {
const { ref, activeKey, activeElement } = useVisibleElement({
activeClass: 'active',
});
console.log('activeKey', activeKey);
console.log('activeElement', activeElement);
return (
<div ref={ref}>
<section style={{height: '100vh'}}>
<p>section 1</p>
</section>
<section style={{height: '100vh'}}>
<p>section 2</p>
</section>
<section style={{height: '100vh'}}>
<p>section 3</p>
</section>
<section style={{height: '100vh'}}>
<p>section 4</p>
</section>
</div>
);
}
useWindowScroll
usage
import { useScrollLock } from '@lani.ground/react-hooks';
export default function Component() {
comst {lockScroll, unlockScroll} = useScrollLock();
useEffect(() => {
lockScroll();
return () => {
unlockScroll();
}
}, [])
return (<>...</>)
}
useCookie
usage
import { useCookies } from '@lani.ground/react-hooks';
import { useEffect } from 'react';
export default function Hooks() {
const { getCookie, setCookie, hasCookie, deleteCookie } = useCookies();
const setTestCookie = () => {
const day = new Date();
day.setMinutes(day.getMinutes() + 1);
setCookie('test', 'true', { expires: 'today' });
};
const checkCookie = () => {
const hasTest = hasCookie('test');
console.log('hasTest', hasTest);
};
useEffect(() => {
const testCookie = getCookie('test');
console.log('testCookie', testCookie);
}, []);
return (
<>
<button type="button" onClick={() => checkCookie()}>
Check Cookie
</button>
<button type="button" onClick={() => setTestCookie()}>
Set Cookie
</button>
<button type="button" onClick={() => deleteCookie('test')}>
Delete Cookie
</button>
</>
);
}