Module

React

Package
purescript-react
Repository
purescript-contrib/purescript-react

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

#ReactComponent Source

data ReactComponent :: Type

A mounted react component

#ReactThis Source

data ReactThis :: Type -> Type -> Type

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

#ReactUnusedSnapshot Source

#TagName Source

type TagName = String

Name of a tag.

#Render Source

type Render = Effect ReactElement

A render effect.

#ComponentWillMount Source

type ComponentWillMount = Effect Unit

A component will mount effect.

#ComponentDidMount Source

type ComponentDidMount = Effect Unit

A component did mount effect.

#ComponentDidCatch Source

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

A component did catch effect.

#ComponentWillReceiveProps Source

type ComponentWillReceiveProps props = props -> Effect Unit

A component will receive props function.

#ShouldComponentUpdate Source

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

A should component update function.

#ComponentWillUpdate Source

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

A component will update function.

#ComponentDidUpdate Source

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

A component did update function.

#ComponentWillUnmount Source

type ComponentWillUnmount = Effect Unit

A component will unmount effect.

#ReactClass Source

data ReactClass :: Type -> Type

React class for components.

#ReactRef Source

data ReactRef :: Type

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

#ReactComponentSpec Source

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

#ReactPureComponentSpec Source

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

#component Source

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

Creates a ReactClass`` inherited fromReact.Component`.

#componentWithDerivedState Source

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

Like component, but takes a getDerivedStateFromProps handler.

#pureComponent Source

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

Creates a ReactClass`` inherited fromReact.PureComponent`.

#pureComponentWithDerivedState Source

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

Like pureComponent, but takes a getDerivedStateFromProps handler.

#statelessComponent Source

statelessComponent :: forall props. (Record props -> ReactElement) -> ReactClass (Record props)

#getProps Source

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

Read the component props.

#getState Source

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

Get the component state.

#setState Source

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

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

#setStateWithCallback Source

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

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

#writeState Source

writeState :: forall all props. ReactThis props (Record all) -> Record all -> Effect Unit

Update component state.

#writeStateWithCallback Source

writeStateWithCallback :: forall all props. ReactThis props (Record all) -> Record all -> Effect Unit -> Effect Unit

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

#modifyState Source

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

Update component state given a modification function.

#modifyStateWithCallback Source

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

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

#forceUpdate Source

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

Force render of a react component.

#forceUpdateWithCallback Source

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

Force render and then run an Effect.

#createElement Source

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

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

#unsafeCreateElement Source

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

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

#createElementDynamic Source

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

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

#unsafeCreateElementDynamic Source

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

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

#createLeafElement Source

createLeafElement :: forall given required. ReactPropFields required given => ReactClass (Record required) -> Record given -> ReactElement

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

#unsafeCreateLeafElement Source

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

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

#createElementTagName Source

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 Source

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.

#SyntheticEventHandler Source

#Children Source

data Children :: Type

Internal representation for the children elements passed to a component

Instances

#childrenToArray Source

childrenToArray :: Children -> Array ReactElement

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

#childrenCount Source

childrenCount :: Children -> Int

Returns the number of children.

#ReactPropFields Source

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

#fragmentWithKey Source

fragmentWithKey :: String -> Array ReactElement -> ReactElement

Creates a keyed fragment.

#Context Source

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

#ContextProvider Source

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

#ContextConsumer Source

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

#createContext Source

createContext :: forall a. a -> Context a

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