@dims/react-hooks
TypeScript icon, indicating that this package has built-in type declarations

0.2.4 • Public • Published

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...");
      }}
    />
  );
}

Readme

Keywords

none

Package Sidebar

Install

npm i @dims/react-hooks

Weekly Downloads

32

Version

0.2.4

License

ISC

Unpacked Size

7.6 kB

Total Files

7

Last publish

Collaborators

  • dims