Skip to content

performAction

Michael Niday edited this page Jun 5, 2018 · 4 revisions

Arguments

  1. action (string): you must specify these actions first in your resource_config file
  2. options (object)

Options:

  • itemId: In POST /contacts/:id this would populate the :id
  • data (object): In POST /contacts this would be body request data
  • filters (Immutable.Map): In GET /contacts this would be query params used in fetching the resource
  • onSuccess (Function): Callback that gets called when ApiClient promise resolves
  • onError (Function): Callback that gets called when request errors

Example

// In a React component

...
  handleGetPerson = (url) => {
    this.props.people.performAction('fetch', {
      itemId: idFromUrl(url),
      responseStrategy: 'ignore',
      onSuccess: ({data}) => {
        this.setState({selectedPersonId: data.id})
        this.fetchPlanet(data.homeworld)
      }
    })
  }
...
export default entities({people: {type: 'people'}})(Component)

Here people is both the name of the container prop provided to Component and the record type defined in records.js

Clone this wiki locally