diff --git a/src/React/Basic/Hooks.purs b/src/React/Basic/Hooks.purs index b5a2f3c..8f1bf18 100644 --- a/src/React/Basic/Hooks.purs +++ b/src/React/Basic/Hooks.purs @@ -7,6 +7,7 @@ module React.Basic.Hooks , ReactChildren , memo , useState + , useState' , UseState , useEffect , useEffectOnce @@ -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) @@ -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