All Projects → JulesGuesnon → Reason-react-hooks

JulesGuesnon / Reason-react-hooks

Licence: other
🧶 Some hooks in ReasonML for reason-react that can be useful

Programming Languages

reason
219 projects

Projects that are alternatives of or similar to Reason-react-hooks

re-use
⚛️ 🎣 A collection of hooks for ReasonReact
Stars: ✭ 27 (+92.86%)
Mutual labels:  reasonml, reason-react, react-hooks
reason-hooks-testing-library
ReasonML bindings for react-hooks-testing-library
Stars: ✭ 24 (+71.43%)
Mutual labels:  reasonml, reason-react, react-hooks
Fullstack Reason
A demo project that shows a fullstack ReasonML/OCaml app–native binary + webapp
Stars: ✭ 164 (+1071.43%)
Mutual labels:  reasonml, reason-react
Bs Material Ui
ReScript bindings for material-ui
Stars: ✭ 185 (+1221.43%)
Mutual labels:  reasonml, reason-react
app-template-rescript-react
Adding ReScript with rescript-react on top of @snowpack/app-template-react
Stars: ✭ 44 (+214.29%)
Mutual labels:  reasonml, reason-react
Reroute
a fast, declarative microrouter for reason-react
Stars: ✭ 120 (+757.14%)
Mutual labels:  reasonml, reason-react
Brisk Reconciler
React.js-like reconciler implemented in OCaml/Reason
Stars: ✭ 124 (+785.71%)
Mutual labels:  reasonml, reason-react
Reason Graphql Fullstack
Fullstack Reason + GraphQL Todo List App
Stars: ✭ 246 (+1657.14%)
Mutual labels:  reasonml, reason-react
Timerlab
⏰ A simple and customizable timer
Stars: ✭ 84 (+500%)
Mutual labels:  reasonml, reason-react
re-typescript
An opinionated attempt at finally solving typescript interop for ReasonML / OCaml.
Stars: ✭ 68 (+385.71%)
Mutual labels:  reasonml, reason-react
Rescript Recoil
Zero-cost bindings to Facebook's Recoil library
Stars: ✭ 115 (+721.43%)
Mutual labels:  reasonml, reason-react
reason-react-lazy-loading
Example project to show how to use components lazy loading in ReasonReact
Stars: ✭ 41 (+192.86%)
Mutual labels:  reasonml, reason-react
Reason Calculator
A calculator built with Reason and reason-react.
Stars: ✭ 110 (+685.71%)
Mutual labels:  reasonml, reason-react
Pure
React in pure Reason that targets native platforms.
Stars: ✭ 135 (+864.29%)
Mutual labels:  reasonml, reason-react
Verified React
Automated reasoning for React/ReasonML
Stars: ✭ 104 (+642.86%)
Mutual labels:  reasonml, reason-react
Rescript Relay
Use Relay with ReasonML.
Stars: ✭ 214 (+1428.57%)
Mutual labels:  reasonml, reason-react
Rescript React Update
useReducer with updates and side effects!
Stars: ✭ 79 (+464.29%)
Mutual labels:  reasonml, reason-react
Introduce Reason Example
An example app made with Create React App which introduces a Reason component
Stars: ✭ 82 (+485.71%)
Mutual labels:  reasonml, reason-react
bs-rsuite-ui-react
Reason bindings for React Suite UI library
Stars: ✭ 26 (+85.71%)
Mutual labels:  reasonml, reason-react
re-cite
Manage citations from your colleagues , friends, movies, your cat or even yourself.
Stars: ✭ 20 (+42.86%)
Mutual labels:  reasonml, reason-react

Reason-react-hooks

this package is a group of various hooks for reason-react that you may want to use.

How to install ?

npm install reason-react-hooks --save
yarn add reason-react-hooks

Then add the dependency to you bsconfig.json

"bs-dependencies": [
	"reason-react-hooks"
],

How to use it ?

What the package contains ?

All the hooks are located under ReasonReactHooks.Hooks

Examples

useVisible

This hook allow you to detect when an element appear on the screen. It will trigger every time the element enter the window, which mean if the element is visible, then not, and visible again, the callback will trigger 2 times.

[@react.component]
let make = () => {
  let (ref, isVisible) = ReasonReactHooks.Hooks.useVisible();

  <div ref>
    {
        isVisible ? "Hello !" : "I'm hidden";
    }
    ->ReasonReact.string
  </div>;
};

useHover

This hook allow you to know when an element is hovered.

[@react.component]
let make = () => {
  let (ref, isHover) = ReasonReactHooks.Hooks.useHover();

  <div ref>
    {
      isHover ? "You're on me !" : "You're not on me !";
    }
    ->ReasonReact.string
  </div>;
};

useDidMount

This hook allow you to do same that with classes and trigger a callback once the component is mounted

[@react.component]
let make = () => {
  ReasonReactHooks.Hooks.useDidMount(~cb=() => Js.log("Component mounted"));

  <div> "Hello world"->ReasonReact.string </div>;
};

useDebounce

This hook allow you to debounce a function. It's pretty useful to deal with input and for performances You can only pass 1 parameter to you callback. If you need more that 1 parameter, consider using an array, a record, a dict...

[@react.component]
let make = () => {
  let (_, setValue) = React.useState(_ => "");
  let debouncedFunction =
    ReasonReactHooks.Hooks.useDebounce(
      ~cb=
        value => {
          setValue(_ => value);
          Js.log(value);
        },
      ~delay=500,
      (),
    );
  <div>
    <input
      type_="text"
      onChange={e => {
        let value = ReactEvent.Form.target(e)##value;
        debouncedFunction(value);
      }}
    />
  </div>;
};

useWindowSize

This hook allow you to get the window height and width. It handle the window resize

[@react.component]
let make = () => {
  let windowSize = ReasonReactHooks.Hooks.useWindowSize();
  let height = windowSize.height;
  let width = windowSize.width;
  <div>
    {j| The window is currently $width x $height|j}->ReasonReact.string
  </div>;
};

useMousePosition

This hook allow you to get the x and y of the mouse.

[@react.component]
let make = () => {
  let mousePosition = ReasonReactHooks.Hooks.useMousePosition();
  let y = mousePosition.y;
  let x = mousePosition.x;
  <div>
    {j| The window is currently $x x $y|j}->ReasonReact.string
  </div>;
};
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].