Skip to content

Commit

Permalink
docs(hooks): add usage example for hooks (#991)
Browse files Browse the repository at this point in the history
The type signatures for the hooks are quite hard to read.

Especially since most parts of it are abstracted away by the brisk-reconciler.
This change makes it easier to discover how to use the common hooks.

![image](https://user-images.githubusercontent.com/18226001/90973151-9b1ac500-e562-11ea-8770-5a88dacc5f33.png)
  • Loading branch information
chinwobble authored Aug 25, 2020
1 parent f63a135 commit 836351d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/UI_Hooks/Effect.rei
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
open Revery_UI.React.Hooks;

/**
{2 Description:}
The Effect Hook lets you perform side effects in function components.
{2 Usage:}
{[
let%hook () = Hooks.effect(OnMount, () => {
// Some side-effect
// Clean-up function
None;
});
]}
*/
let effect:
(
Effect.condition('a),
Expand Down
11 changes: 11 additions & 0 deletions src/UI_Hooks/Reducer.rei
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
open Revery_UI.React.Hooks;

/**
{2 Description:}
An alternative to Hooks.state. Accepts a reducer of type (action, state) => newState, and returns the current state paired with a dispatch function.
{2 Usage:}
{[
let%hook (state, dispatch) = Hooks.reducer(~initialState={counter:0}, reduce);
]}
*/
let reducer:
(~initialState: 'a, ('b, 'a) => 'a, t(Reducer.t('a) => 'c, 'd)) =>
(('a, 'b => unit), t('c, 'd));
11 changes: 11 additions & 0 deletions src/UI_Hooks/State.rei
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
open Revery_UI.React.Hooks;

/**
{2 Description:}
TODO
{2 Usage:}
{[
let%hook (state, setState) = Hooks.state(0);
]}
*/
let state:
('a, t(State.t('a) => 'b, 'c)) => (('a, ('a => 'a) => unit), t('b, 'c));

0 comments on commit 836351d

Please sign in to comment.