Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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