Options
All
  • Public
  • Public/Protected
  • All
Menu

Props: CallableAsyncProps extends Omit<AsyncProps, 'children' | 'params'>

A render-prop component that injects an AsyncLifecycle for any AsyncOperation into the component tree. Identical to Async, except that instead of accepting params as a prop, it passes call(...params: Params) to its children. As such, CallableAsync gives the children control over when the operation is executed - typically as a result of a user interaction. This can be used for user-initiated asynchronous calls, such as saving a form.

The following example invokes save when the button is clicked:

// type save = (entity: Entity) => Promise

<CallableAsync operation={save}>
  {(state, call) =>
    <div>
      {
        // If the Promise is rejected, render the error.
        state.error ? <span className="error">{state.error}</span>
          // If the Promise resolves, render a success message.
          : state.status === 'complete' ? <span className="success">Entity saved successfully.</span>
          // If the operation is active, render a loading indicator.
          : state.status === 'active' && <span className="loading" />
      }
      <button
        onClick={() => save(entity)}>
        Save
      </button>
    </div>}
</CallableAsync>

The implementation of CallableAsync is trivial. It is a stateful wrapper around Async that calls setState(params) when call(params) is invoked. More complex use cases that are not met by Async or CallableAsync can be achieved using a similar strategy.

Type parameters

  • Data

  • Params: any[]

  • SS

Hierarchy

Index

Constructors

constructor

Properties

context

context: any

props

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

refs

refs: object

Type declaration

  • [key: string]: ReactInstance

state

state: CallableAsyncState<Params>

Methods

Optional UNSAFE_componentWillMount

  • UNSAFE_componentWillMount(): void

Optional UNSAFE_componentWillReceiveProps

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

Optional UNSAFE_componentWillUpdate

call

  • call(...params: Params): 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

  • 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<CallableAsyncProps<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

forceUpdate

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

    • Optional callBack: undefined | function

    Returns void

Optional getSnapshotBeforeUpdate

  • 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 CallableAsyncState<Params>

    Parameters

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

    Returns void

Optional shouldComponentUpdate

  • 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

    Returns boolean

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc