Module

React

This module defines foreign types and functions which wrap React's functionality.

#TagName

type TagName = String

Name of a tag.

#ReactComponent

data ReactComponent :: Type

A mounted react component

#ReactThis

data ReactThis :: Type -> Type -> Type

A reference to a component, essentially React's this.

#ReactUnusedSnapshot

#SyntheticEventHandler

#Render

type Render = Effect ReactElement

A render effect.

#ComponentWillMount

type ComponentWillMount = Effect Unit

A component will mount effect.

#ComponentDidMount

type ComponentDidMount = Effect Unit

A component did mount effect.

#ComponentDidCatch

type ComponentDidCatch = Error -> { componentStack :: String } -> Effect Unit

A component did catch effect.

#ComponentWillReceiveProps

type ComponentWillReceiveProps props = props -> Effect Unit

A component will receive props function.

#ShouldComponentUpdate

type ShouldComponentUpdate props state = props -> state -> Effect Boolean

A should component update function.

#ComponentWillUpdate

type ComponentWillUpdate props state = props -> state -> Effect Unit

A component will update function.

#ComponentDidUpdate

type ComponentDidUpdate props state snapshot = props -> state -> snapshot -> Effect Unit

A component did update function.

#GetSnapshotBeforeUpdate

type GetSnapshotBeforeUpdate props state snapshot = props -> state -> Effect snapshot

#ComponentWillUnmount

type ComponentWillUnmount = Effect Unit

A component will unmount effect.

#ReactSpecRequired

type ReactSpecRequired state r = (state :: state, render :: Render | r)

Required fields for constructing a ReactClass.

#ReactSpecUnsafe

type ReactSpecUnsafe props state r = (unsafeComponentWillMount :: ComponentWillMount, unsafeComponentWillReceiveProps :: ComponentWillReceiveProps props, unsafeComponentWillUpdate :: ComponentWillUpdate props state | r)

#ReactSpecOptional

type ReactSpecOptional props state snapshot r = (componentDidMount :: ComponentDidMount, componentDidCatch :: ComponentDidCatch, componentWillUnmount :: ComponentWillUnmount, componentDidUpdate :: ComponentDidUpdate props state snapshot, getSnapshotBeforeUpdate :: GetSnapshotBeforeUpdate props state snapshot | ReactSpecUnsafe props state r)

Optional fields for constructing a ReactClass.

#ReactSpecShouldComponentUpdate

type ReactSpecShouldComponentUpdate props state = (shouldComponentUpdate :: ShouldComponentUpdate props state)

#ReactSpecAll

type ReactSpecAll props state snapshot = (ReactSpecRequired state) + (ReactSpecOptional props state snapshot) + (ReactSpecShouldComponentUpdate props state)

#ReactSpecPure

type ReactSpecPure props state snapshot = (ReactSpecRequired state) + (ReactSpecOptional props state snapshot ())

#ReactClassConstructor

type ReactClassConstructor props state r = ReactThis props state -> Effect ({  | r })

The signature for a ReactClass constructor. A constructor takes the ReactThis context and returns a record with appropriate lifecycle methods.

#ReactComponentSpec

class ReactComponentSpec props state snapshot (given :: # Type) (spec :: # Type) 

Instances

#ReactPureComponentSpec

class ReactPureComponentSpec props state snapshot (given :: # Type) (spec :: # Type) 

Instances

#component

component :: forall props state snapshot given spec. ReactComponentSpec ({  | props }) ({  | state }) snapshot given spec => String -> ReactClassConstructor ({  | props }) ({  | state }) given -> ReactClass ({  | props })

Creates a ReactClass`` inherited fromReact.Component`.

#componentWithDerivedState

componentWithDerivedState :: forall props state snapshot given spec. ReactComponentSpec ({  | props }) ({  | state }) snapshot given spec => String -> ({  | props } -> {  | state } -> {  | state }) -> ReactClassConstructor ({  | props }) ({  | state }) given -> ReactClass ({  | props })

Like component, but takes a getDerivedStateFromProps handler.

#pureComponent

pureComponent :: forall props state snapshot given spec. ReactPureComponentSpec ({  | props }) ({  | state }) snapshot given spec => String -> ReactClassConstructor ({  | props }) ({  | state }) given -> ReactClass ({  | props })

Creates a ReactClass`` inherited fromReact.PureComponent`.

#pureComponentWithDerivedState

pureComponentWithDerivedState :: forall props state snapshot given spec. ReactPureComponentSpec ({  | props }) ({  | state }) snapshot given spec => String -> ({  | props } -> {  | state } -> {  | state }) -> ReactClassConstructor ({  | props }) ({  | state }) given -> ReactClass ({  | props })

Like pureComponent, but takes a getDerivedStateFromProps handler.

#statelessComponent

statelessComponent :: forall props. ({  | props } -> ReactElement) -> ReactClass ({  | props })

#ReactClass

data ReactClass :: Type -> Type

React class for components.

#ReactRef

data ReactRef :: Type

Type for React refs. This type is opaque, but you can use Data.Foreign and DOM to validate the underlying representation.

#getProps

getProps :: forall props state. ReactThis props state -> Effect props

Read the component props.

#getState

getState :: forall props state. ReactThis props state -> Effect state

Get the component state.

#setState

setState :: forall props given rest all. Union given rest all => ReactThis props ({  | all }) -> {  | given } -> Effect Unit

Update component state given some sub-set of state properties.

#setStateWithCallback

setStateWithCallback :: forall props given rest all. Union given rest all => ReactThis props ({  | all }) -> {  | given } -> Effect Unit -> Effect Unit

Update component state given some sub-set of state properties, while also invoking a callback when applied.

#writeState

writeState :: forall props all. ReactThis props ({  | all }) -> {  | all } -> Effect Unit

Update component state.

#writeStateWithCallback

writeStateWithCallback :: forall props all. ReactThis props ({  | all }) -> {  | all } -> Effect Unit -> Effect Unit

Update component state, while also invoking a callback when applied.

#modifyState

modifyState :: forall props state. ReactThis props state -> (state -> state) -> Effect Unit

Update component state given a modification function.

#modifyStateWithCallback

modifyStateWithCallback :: forall props state. ReactThis props state -> (state -> state) -> Effect Unit -> Effect Unit

Update component state given a modification function, while also invoking a callback when applied.

#forceUpdate

forceUpdate :: forall props state. ReactThis props state -> Effect Unit

Force render of a react component.

#forceUpdateWithCallback

forceUpdateWithCallback :: forall props state. ReactThis props state -> Effect Unit -> Effect Unit

Force render and then run an Effect.

#ReactPropFields

class ReactPropFields (required :: # Type) (given :: # Type) 

Instances

#ReservedReactPropFields

#createElement

createElement :: forall required given. ReactPropFields required given => ReactClass { children :: Children | required } -> {  | given } -> Array ReactElement -> ReactElement

Create an element from a React class spreading the children array. Used when the children are known up front.

#unsafeCreateElement

unsafeCreateElement :: forall props. ReactClass { children :: Children | props } -> {  | props } -> Array ReactElement -> ReactElement

An unsafe version of createElement which does not enforce the reserved properties "key" and "ref".

#createElementDynamic

createElementDynamic :: forall required given. ReactPropFields required given => ReactClass { children :: Children | required } -> {  | given } -> Array ReactElement -> ReactElement

Create an element from a React class passing the children array. Used for a dynamic array of children.

#unsafeCreateElementDynamic

unsafeCreateElementDynamic :: forall props. ReactClass { children :: Children | props } -> {  | props } -> Array ReactElement -> ReactElement

An unsafe version of createElementDynamic which does not enforce the reserved properties "key" and "ref".

#createLeafElement

createLeafElement :: forall required given. ReactPropFields required given => ReactClass {  | required } -> {  | given } -> ReactElement

Create an element from a React class that does not require children.

#unsafeCreateLeafElement

unsafeCreateLeafElement :: forall props. ReactClass props -> props -> ReactElement

An unsafe version of createLeafElement which does not enforce the reserved properties "key" and "ref".

#createElementTagName

createElementTagName :: forall props. TagName -> props -> Array ReactElement -> ReactElement

Create an element from a tag name spreading the children array. Used when the children are known up front.

#createElementTagNameDynamic

createElementTagNameDynamic :: forall props. TagName -> props -> Array ReactElement -> ReactElement

Create an element from a tag name passing the children array. Used for a dynamic array of children.

#Children

data Children :: Type

Internal representation for the children elements passed to a component

Instances

#childrenToArray

childrenToArray :: Children -> Array ReactElement

Internal conversion function from children elements to an array of React elements

#childrenCount

childrenCount :: Children -> Int

Returns the number of children.

#fragmentWithKey

fragmentWithKey :: String -> Array ReactElement -> ReactElement

Creates a keyed fragment.

#Context

type Context a = { consumer :: ContextConsumer a, provider :: ContextProvider a }

#ContextProvider

type ContextProvider a = ReactClass { children :: Children, value :: a }

#ContextConsumer

type ContextConsumer a = ReactClass { children :: a -> ReactElement }

#createContext

createContext :: forall a. a -> Context a

Create a new context provider/consumer pair given a default value.

Modules