npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

reason-react-hooks

v0.4.2

Published

Some hooks in ReasonML for reason-react that can be useful.

Downloads

29

Readme

Reason-react-hooks

this package is a group of various hooks for reason-react that you may want to use.

How to install ?

npm install reason-react-hooks --save
yarn add reason-react-hooks

Then add the dependency to you bsconfig.json

"bs-dependencies": [
	"reason-react-hooks"
],

How to use it ?

What the package contains ?

All the hooks are located under ReasonReactHooks.Hooks

:rotating_light: Don't use any other module, for now bucklescript private module system isn't working but when it will, only ReasonReactHooks.Hooks will be expose.

Examples

useVisible

This hook allow you to detect when an element appear on the screen. It will trigger every time the element enter the window, which mean if the element is visible, then not, and visible again, the callback will trigger 2 times.

[@react.component]
let make = () => {
  let (ref, isVisible) = ReasonReactHooks.Hooks.useVisible();

  <div ref>
    {
        isVisible ? "Hello !" : "I'm hidden";
    }
    ->ReasonReact.string
  </div>;
};

useHover

This hook allow you to know when an element is hovered.

[@react.component]
let make = () => {
  let (ref, isHover) = ReasonReactHooks.Hooks.useHover();

  <div ref>
    {
      isHover ? "You're on me !" : "You're not on me !";
    }
    ->ReasonReact.string
  </div>;
};

useDidMount

This hook allow you to do same that with classes and trigger a callback once the component is mounted

[@react.component]
let make = () => {
  ReasonReactHooks.Hooks.useDidMount(~cb=() => Js.log("Component mounted"));

  <div> "Hello world"->ReasonReact.string </div>;
};

useDebounce

This hook allow you to debounce a function. It's pretty useful to deal with input and for performances You can only pass 1 parameter to you callback. If you need more that 1 parameter, consider using an array, a record, a dict...

[@react.component]
let make = () => {
  let (_, setValue) = React.useState(_ => "");
  let debouncedFunction =
    ReasonReactHooks.Hooks.useDebounce(
      ~cb=
        value => {
          setValue(_ => value);
          Js.log(value);
        },
      ~delay=500,
      (),
    );
  <div>
    <input
      type_="text"
      onChange={e => {
        let value = ReactEvent.Form.target(e)##value;
        debouncedFunction(value);
      }}
    />
  </div>;
};

useWindowSize

This hook allow you to get the window height and width. It handle the window resize

[@react.component]
let make = () => {
  let windowSize = ReasonReactHooks.Hooks.useWindowSize();
  let height = windowSize.height;
  let width = windowSize.width;
  <div>
    {j| The window is currently $width x $height|j}->ReasonReact.string
  </div>;
};

useMousePosition

This hook allow you to get the x and y of the mouse.

[@react.component]
let make = () => {
  let mousePosition = ReasonReactHooks.Hooks.useMousePosition();
  let y = mousePosition.y;
  let x = mousePosition.x;
  <div>
    {j| The window is currently $x x $y|j}->ReasonReact.string
  </div>;
};