Options
All
  • Public
  • Public/Protected
  • All
Menu

Class CallableEffect<Data, Params, S, SS, S>

CallableEffect is a React render-prop component that injects FxState for any side effect into its children. It gives the consumer control over when the side-effect is executed. This can be used for user-initiated side-effect calls, such as submitting a search or deleting a record. Each instance of a CallableEffect will own its own unique FxState and FxActions. On unmount, the component will destroy its FxState, cleaning up after itself.

The following example initiates the given side-effect when the button is clicked. While it is pending, it renders a loading indicator. When it resolves, it renders the value that was passed to resolve(). If the Promise is rejected, it renders the error that was passed to reject().

example
// typeof effect: (p1: number, p2: string) => Promise<string>

<CallableEffect effect={effect} store={store}>
  {(state, call) =>
    <div>
      {state.error ? <span className="error">{state.error}</span>
         : state.data ? <span className="response">{state.data}</span>
: state.status === 'active' && <span className="loading" />}
      <button onClick={() => call(123, 'abc')}>call effect</button>
    </div>}
</CallableEffect>

Type parameters

  • Data

  • Params: any[]

  • S

  • SS

  • S

Hierarchy

Index

Constructors

constructor

Properties

context

context: any

fxActions

fxActions: FxActionCreators<Data, Params>

props

props: Readonly<object> & Readonly<CallableEffectProps<Data, Params>>

refs

refs: object

Type declaration

  • [key: string]: ReactInstance

state

state: Readonly<S>

Methods

Optional UNSAFE_componentWillMount

  • UNSAFE_componentWillMount(): void

Optional UNSAFE_componentWillReceiveProps

  • UNSAFE_componentWillReceiveProps(nextProps: Readonly<CallableEffectProps<Data, Params>>, nextContext: any): void

Optional UNSAFE_componentWillUpdate

  • UNSAFE_componentWillUpdate(nextProps: Readonly<CallableEffectProps<Data, Params>>, nextState: Readonly<S>, nextContext: any): void

Optional componentDidCatch

  • componentDidCatch(error: Error, errorInfo: ErrorInfo): void
  • Catches exceptions generated in descendant components. Unhandled exceptions will cause the entire component tree to unmount.

    Parameters

    • error: Error
    • errorInfo: ErrorInfo

    Returns void

Optional componentDidMount

  • componentDidMount(): void
  • Called immediately after a component is mounted. Setting state here will trigger re-rendering.

    Returns void

Optional componentDidUpdate

  • componentDidUpdate(prevProps: Readonly<CallableEffectProps<Data, Params>>, prevState: Readonly<S>, snapshot?: SS): void
  • Called immediately after updating occurs. Not called for the initial render.

    The snapshot is only present if getSnapshotBeforeUpdate is present and returns non-null.

    Parameters

    Returns void

Optional componentWillMount

  • componentWillMount(): void

Optional componentWillReceiveProps

  • componentWillReceiveProps(nextProps: Readonly<CallableEffectProps<Data, Params>>, nextContext: any): void

Optional componentWillUnmount

  • componentWillUnmount(): void
  • Called immediately before a component is destroyed. Perform any necessary cleanup in this method, such as cancelled network requests, or cleaning up any DOM elements created in componentDidMount.

    Returns void

Optional componentWillUpdate

  • componentWillUpdate(nextProps: Readonly<CallableEffectProps<Data, Params>>, nextState: Readonly<S>, nextContext: any): void

forceUpdate

  • forceUpdate(callBack?: undefined | function): void
  • Parameters

    • Optional callBack: undefined | function

    Returns void

Optional getSnapshotBeforeUpdate

  • getSnapshotBeforeUpdate(prevProps: Readonly<CallableEffectProps<Data, Params>>, prevState: Readonly<S>): SS | null
  • Runs before React applies the result of render to the document, and returns an object to be given to componentDidUpdate. Useful for saving things such as scroll position before render causes changes to it.

    Note: the presence of getSnapshotBeforeUpdate prevents any of the deprecated lifecycle events from running.

    Parameters

    Returns SS | null

render

  • render(): Element

setState

  • setState<K>(state: function | null | S | object, callback?: undefined | function): void
  • Type parameters

    • K: keyof S

    Parameters

    • state: function | null | S | object
    • Optional callback: undefined | function

    Returns void

Optional shouldComponentUpdate

  • shouldComponentUpdate(nextProps: Readonly<CallableEffectProps<Data, Params>>, nextState: Readonly<S>, nextContext: any): boolean
  • Called to determine whether the change in props and state should trigger a re-render.

    Component always returns true. PureComponent implements a shallow comparison on props and state and returns true if any props or states have changed.

    If false is returned, Component#render, componentWillUpdate and componentDidUpdate will not be called.

    Parameters

    • nextProps: Readonly<CallableEffectProps<Data, Params>>
    • nextState: Readonly<S>
    • nextContext: any

    Returns boolean

Generated using TypeDoc