Module

Elmish.Hooks.UseRef

Package
purescript-elmish-hooks
Repository
collegevine/purescript-elmish-hooks

#UseRef Source

type UseRef :: Type -> HookType' -> HookType'type UseRef el = UseState (Maybe el)

#useRef Source

useRef :: forall @el. Hook (UseRef el) ((Maybe el) /\ (Ref el))

The useRef hook returns a Hook encapsulating an element paired with a setter for that element. This setter can be passed to a ref prop to get a reference to an element.

view :: ReactElement
view = Hooks.component Hooks.do
  inputEl /\ inputRef <- useRef
  let onButtonClick = traverse_ (focus <<< HTMLInputElement.toHTMLElement) inputEl
  Hooks.pure $
    H.fragment
    [ H.input_ "form-control" { ref: inputRef, defaultValue: "" }
    , H.button_ "btn btn-primary" { onClick: onButtonClick } "Focus the input"
    ]