React Hooks
Just another hooks collection.
Hooks
useWindowResize
Simple addEventListener('resize') hook.
function MyComponent() {
useWindowResize(
() => {
console.log("resized");
},
true,
50,
);
}
useSmoothScroll
Cross-browser smooth scrolling.
function MyComponent() {
const smooth = useSmoothScroll();
return (
<button
onClick={() => {
smooth.scrollTo(0, 200, () => {
console.log("end");
});
}}
>
Scroll down 200px
</button>
);
}
useTruncateLines
Truncated text to specific number of lines.
function MyComponent() {
const truncate = useTruncateLines({ lines: 2 });
return (
<div
ref={(node) => {
truncate(node, "Some very long text...");
}}
/>
);
}