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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@glennsl/rescript-react-hooks

v1.0.0

Published

Better hooks for rescript-react

Downloads

1

Readme

rescript-react-hooks

Better hooks for rescript-react.

npm Issues Last Commit

This replaces most hooks that come with rescript-react with improved versions. More specifically, it provides:

  • Both lazy and non-lazy versions of state hooks
  • Hooks that trigger when dependencies change can be passed a custom equality function.
  • Dependencies are compareed using structural equality by default, as you'd expect.
  • Properly named effect hooks that don't require guessing their behaviour based on seemingly arbitrary numberical suffixes.
  • More ergonomic and idiomatic API design, using optional arguments instead of idioms designed for dynamic typing.
  • A useResource hook tailored for managing resources.

Example

Hooks.useEffectOnce(() => Js.log("mounted"))
Hooks.useEffectAlways(~beforeRender=true, () => Js.log("about to render"))
Hooks.useEffectAlways(() => Js.log("rendered"))

// Use custom euqlity function to ignore nulls
Hooks.useEffect(
  () => Js.log2("Got element", elRef.current),
  ~equal=(a, b) => b.current == Js.Nullable.null || a == b,
  ~on=elRef,
)

// setTiemout returns a timerId that will be passed to clearTiemout on release
Hooks.useResource(
  ~on=tickEnabled,
  () => Js.Global.setTimeout(() => Js.log("tick"), 1000),
  ~release=Js.Global.clearTimeout,
)

Installation

npm install --save @glennsl/rescript-react-hooks

Then add @glennsl/rescript-react-hooks to bs-dependencies in your bsconfig.json:

{
  ...
  "bs-dependencies": ["@glennsl/rescript-react-hooks"]
}

Documentation

See doc comments in Hooks.resi

License

This work is dual-licensed under LGPL 3.0 and MPL 2.0. You can choose between one of them if you use this work. Please see LICENSE.LGPL-3.0 and LICENSE.MPL-2.0 for the full text of each license. SPDX-License-Identifier: LGPL-3.0 OR MPL-2.0

Changes

1.0.0

  • Initial release