Module
React.Basic.Events
- Package
- purescript-react-basic
- Repository
- lumihq/purescript-react-basic
#EventHandler Source
type EventHandler = EffectFn1 SyntheticEvent UnitAn event handler, which receives a SyntheticEvent and performs some
effects in return.
#SyntheticEvent Source
data SyntheticEvent :: TypeEvent data that we receive from React.
#EventFn Source
newtype EventFn a bEncapsulates 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 bUnsafely 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) -> EventHandlerCreate an EventHandler, given an EventFn and a callback.
For example:
input { onChange: handler targetValue
\value -> setState \_ -> { value }
}
#handler_ Source
handler_ :: Effect Unit -> EventHandlerCreate 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 \_ -> { ... }
}