@iteam/bs-hooks

A collection of reusable hooks for ReasonML

Usage no npm install needed!

<script type="module">
  import iteamBsHooks from 'https://cdn.skypack.dev/@iteam/bs-hooks';
</script>

README

Iteam Hooks for ReasonML

This is port of @iteam/hooks for ReasonML/BuckleScript. Still a work in progress.

Installation

npm install @iteam/bs-hooks

Add @iteam/bs-hooks to bs-dependencies in bsconfig.json

Available Hooks

useToggle

useToggle(~initialState: option(bool), unit): (bool, unit => unit)

Example

[@react.component]
let make = () => {
  let (isAlive, toggleValue) = IteamHooks.useToggle();

  <button onClick={_ => toggleValue()}>
    {
      isAlive ? {j|🚀|j} : {j|😴|j};
    }
    ->React.string
  </button>;
};

useQueryParam

Gets a value from a specified query param

useQueryParam(~param: Js.Dict.key): string

Example

[@react.component]
let make = () => {
  let param = IteamHooks.useQueryParam(~param="sweetParam");

  <div>
    {"That's a nice query param with the value " ++ param |> React.string}
  </div>;
};