Skip to content

Commit 4725768

Browse files
authored
Merge pull request #24 from jvliwanag/use-state-const
Add useStateConst where update is always const
2 parents ed479a3 + 3e8b10d commit 4725768

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/React/Basic/Hooks.purs

+9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module React.Basic.Hooks
77
, ReactChildren
88
, memo
99
, useState
10+
, useState'
1011
, UseState
1112
, useEffect
1213
, useEffectOnce
@@ -39,6 +40,7 @@ module React.Basic.Hooks
3940
) where
4041

4142
import Prelude hiding (bind, discard)
43+
import Data.Bifunctor (rmap)
4244
import Data.Function.Uncurried (Fn2, mkFn2)
4345
import Data.Maybe (Maybe)
4446
import Data.Newtype (class Newtype)
@@ -165,6 +167,13 @@ useState initialState =
165167
unsafeHook do
166168
runEffectFn2 useState_ (mkFn2 Tuple) initialState
167169

170+
useState' ::
171+
forall state.
172+
state ->
173+
Hook (UseState state) (state /\ (state -> Effect Unit))
174+
useState' initialState =
175+
useState initialState <#> rmap (_ <<< const)
176+
168177
foreign import data UseState :: Type -> Type -> Type
169178

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

0 commit comments

Comments
 (0)