@opendevtools/rescript-hooks

0.1.5 • Public • Published

Hooks for ReasonML

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

Installation

npm install @opendevtools/rescript-hooks

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

Available Hooks

useToggle

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

initialState is set to false by default, that's why it's an option(bool)

Example

[@react.component]
let make = () => {
  let (isAlive, toggleValue) = OpenDevToolsHooks.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 = OpenDevToolsHooks.useQueryParam(~param="sweetParam");

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

/@opendevtools/rescript-hooks/

    Package Sidebar

    Install

    npm i @opendevtools/rescript-hooks

    Weekly Downloads

    0

    Version

    0.1.5

    License

    MIT

    Unpacked Size

    6.99 kB

    Total Files

    14

    Last publish

    Collaborators

    • believer
    • dubbelnisse