Introducing Halogen Hooks

Quick update on Halogen Hooks: there have been a couple new releases over the last few weeks, which in sum:

  1. Simplifies the type signatures when you’re writing Hooks of your own
  2. Introduces some performance improvements, including memoComponent to control when to render when receiving new input
  3. Replaces state tokens with a modifyState function
  4. Fixes some bugs and introduces a full test suite for Hooks – in the future, this will be released as its own package so you can test your own custom Hooks, too

@JordanMartinez has been particularly helpful and active in contributing to these releases, so many thanks to you. If you’ve been using Hooks I highly recommend updating! I suspect the current version, 0.3.0, will be stable for some time.

1 Like

Thanks so much for Halogen Hooks!
I’ve been using it since its inception and it made my life so much easier.

2 Likes

During your work, have you come across any hooks that you think would be worth adding to halogen-hooks-extra?

Oh, I wasn’t aware of halogen-hooks-extra.
Most of my custom hooks are specific to my application, but there’s one that could be useful for other people. I made a throttling hook out of the debouncer one from the examples.

1 Like

What’s the difference between the throttling hook and useDebouncer?

useDebouncer only runs the action if no new values are passed for the length of the interval you specify. The throttling hook will run the action continuously, but at most once every interval.

For instance, let’s say you need to update something for every mouse movement, and you set a 100ms interval. useDebouncer will only run the action once the mouse move events stop for 100ms. The throttling hook will make the update happen every 100ms and will only stop if no new values are passed.

Ah, gotcha! Yeah, that would definitely be useful. Would you mind submitting a PR that adds that hook?

Will do! I’ll add an example too.