Skip to content

Commit

Permalink
Merge pull request #24 from jvliwanag/use-state-const
Browse files Browse the repository at this point in the history
Add useStateConst where update is always const
  • Loading branch information
megamaddu authored Apr 29, 2020
2 parents ed479a3 + 3e8b10d commit 4725768
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/React/Basic/Hooks.purs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module React.Basic.Hooks
, ReactChildren
, memo
, useState
, useState'
, UseState
, useEffect
, useEffectOnce
Expand Down Expand Up @@ -39,6 +40,7 @@ module React.Basic.Hooks
) where

import Prelude hiding (bind, discard)
import Data.Bifunctor (rmap)
import Data.Function.Uncurried (Fn2, mkFn2)
import Data.Maybe (Maybe)
import Data.Newtype (class Newtype)
Expand Down Expand Up @@ -165,6 +167,13 @@ useState initialState =
unsafeHook do
runEffectFn2 useState_ (mkFn2 Tuple) initialState

useState' ::
forall state.
state ->
Hook (UseState state) (state /\ (state -> Effect Unit))
useState' initialState =
useState initialState <#> rmap (_ <<< const)

foreign import data UseState :: Type -> Type -> Type

-- | Runs the given effect when the component is mounted and any time the given
Expand Down

0 comments on commit 4725768

Please sign in to comment.