From 7019a75c95ab9574758185bf679823b521dcbdb3 Mon Sep 17 00:00:00 2001 From: Peter Murphy <26548438+ptrfrncsmrph@users.noreply.github.com> Date: Fri, 25 Dec 2020 18:59:10 -0500 Subject: [PATCH] Add examples to useEffect docs --- src/React/Basic/Hooks.purs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/React/Basic/Hooks.purs b/src/React/Basic/Hooks.purs index 3c1af09..a3895df 100644 --- a/src/React/Basic/Hooks.purs +++ b/src/React/Basic/Hooks.purs @@ -183,7 +183,22 @@ foreign import data UseState :: Type -> Type -> Type -- | Runs the given effect when the component is mounted and any time the given -- | dependencies change. The effect should return its cleanup function. For -- | example, if the effect registers a global event listener, it should return --- | and Effect which removes the listener. +-- | an Effect which removes the listener. +-- | +-- | ```purs +-- | useEffect deps do +-- | timeoutId <- setTimeout 1000 (logShow deps) +-- | pure (clearTimeout timeoutId) +-- | ``` +-- | +-- | If no cleanup is needed, use `pure (pure unit)` or `pure mempty` to return +-- | a no-op Effect +-- | +-- | ```purs +-- | useEffect deps do +-- | logShow deps +-- | pure mempty +-- | ``` useEffect :: forall deps. Eq deps =>