Skip to content
This repository has been archived by the owner on Jul 23, 2022. It is now read-only.

lumihq/purescript-react-select-basic

Repository files navigation

purescript-react-select-basic

react-basic bindings for react-select

Build Status

Docs

Available on Pursuit

Example

module Example where

import Prelude

import Data.Maybe (Maybe(Nothing), maybe)
import Data.Nullable (toMaybe)
import Effect.Uncurried (mkEffectFn1)
import React.Basic (ReactComponent, createElement, react)
import React.Basic.ReactSelect (singleSelect)

component :: ReactComponent {}
component = react { displayName: "BasicExample", initialState, receiveProps, render }
  where
    initialState =
      { selectedValue: Nothing
      }

    receiveProps _ _ _ =
      pure unit

    render _ state setState =
      createElement singleSelect
        { value: maybe "" _.value state.selectedValue
        , options
        , onChange: mkEffectFn1 $ \newValue ->
            setState _ { selectedValue = toMaybe newValue }
        }

    options =
      [ { label: "A"
        , value: "a"
        }
      , { label: "B"
        , value: "b"
        }
      , { label: "C"
        , value: "c"
        }
      ]