1.0.0 • Published 2 years ago

@sh4/hooks v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

@sh4/hooks

Collection of my custom React hooks.

Instalation

npm i @sh4/hooks

Usage

  1. useWindowScroll() - get x axis, y axis and window scroll direction (up, down, left, right)

Window scroll

Reference

Default value for delay / throttle (milisecond) is 0

interface Scroll {
  x: number;
  y: number;
  direction: "up" | "down" | "right" | "left" | undefined;
}
const useWindowScroll = (delay = 0): Scroll => {};

Example

import React from "react";
import { useWindowScroll } from "@saifudinhasan/hooks";

const Component = () => {
  const { x, y, direction } = useWindowScroll(200);

  useEffect(
    {
      // do something
    },
    [direction]
  );

  return <div />;
};

export default Component;