Module

React.Basic.Events

Package
purescript-react-basic
Repository
lumihq/purescript-react-basic

#EventHandler Source

type EventHandler = EffectFn1 SyntheticEvent Unit

An event handler, which receives a SyntheticEvent and performs some effects in return.

#SyntheticEvent Source

data SyntheticEvent :: Type

Event data that we receive from React.

#EventFn Source

newtype EventFn a b

Encapsulates a safe event operation. EventFns can be composed to perform multiple operations.

For example:

input { onChange: handler (preventDefault >>> targetValue)
                    \value -> setState \_ -> { value }
      }

Instances

#unsafeEventFn Source

unsafeEventFn :: forall b a. (a -> b) -> EventFn a b

Unsafely create an EventFn. This function should be avoided as it can allow a SyntheticEvent to escape its scope. Accessing a React event's properties is only valid in a synchronous event callback.

Instead, use the helper functions specific to your platform, such as React.Basic.DOM.Events.

#handler Source

handler :: forall a. EventFn SyntheticEvent a -> (a -> Effect Unit) -> EventHandler

Create an EventHandler, given an EventFn and a callback.

For example:

input { onChange: handler targetValue
                    \value -> setState \_ -> { value }
      }

#handler_ Source

handler_ :: Effect Unit -> EventHandler

Create an EventHandler which discards the SyntheticEvent.

For example:

input { onChange: handler_ (setState \_ -> { value })
      }

#merge Source

merge :: forall r fns_list fns a. RowToList fns fns_list => Merge fns_list fns a r => Record fns -> EventFn a (Record r)

Merge multiple EventFn operations and collect their results.

For example:

input { onChange: handler (merge { targetValue, timeStamp })
                    \{ targetValue, timeStamp } -> setState \_ -> { ... }
      }

#Merge Source

class Merge (rl :: RowList) fns a r | rl -> fns, rl a -> r where

Members

Instances