Bagon Hooks

v0.0.3

A collection of zero-dependency hooks for SolidJS forked directly from Mantine Hooks, with some improvements.

> install bagon-hooks

useCounter

A hook that returns a signal with a counter value and functions to increment, decrement, set and reset the counter.

5

useOs

Returns the current OS

Current OS: undetermined

useClickOutside

Detects clicks outside a ref

No detections

useHotkeys

Handle hotkeys easily

ctrl + a
ctrl + Enter
shift + g

useHover

Detects hovers on a ref

No detections

useIdle

Returns if user has been idle after some milliseconds

Is Idle (1s):true

useMounted

Returns true if component is mounted. Useful for rendering only on client-side.

useNetwork

Returns information about current user's network connection. Try going offline on DevTools.

{
  "online": true
}

useResizeObserver

Returns information about a resizable element. This is more low-level but gives you more than just width and height.

{
  "rect": {
    "x": 0,
    "y": 0,
    "width": 0,
    "height": 0,
    "top": 0,
    "left": 0,
    "bottom": 0,
    "right": 0
  }
}
Resize Me

useElementSize

Returns width and height of a resizable element. An abstraction over useResizeObserver.

Width: 0.00Height: 0.00
Resize Me

useToggle

A hook that toggles between two or multiple values (by implementing a common state pattern). Dev Note: Personally this can be called `useCycle` instead since it cycles through the options.

🍎 apple
🍊 orange
🍇 grape
🥝 kiwi

useFavicon

Appends <link /> element to head component with given favicon url. The hook is not called during server side rendering.

useLocalStorage

A hook that allows using value from the localStorage as a signal. The hook works exactly the same way as createSignal, but also writes the value to the localStorage. It even works between tabs!

To test, try changing the value with two tabs open.

Favorite Fruit: apple

useEyeDropper

A hook that gives you the ability to open the browser's EyeDropper API and save it to a signal.

Picked Color: