Skip to content

Add useStateConst where update is always const #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 29, 2020
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