Custom Actions

  • You can configure custom actions:

const url = 'https://foo.com/users/:id';
export const {types, actions, reducers} = createResource({
  name: 'user',
  url,
  actions: {
    run: {method: 'POST', gerundName: 'running', url: './run'},
    merge: {method: 'POST', isArray: true}
  }
});
  • It will generate the following action creators:

// Action creators available to interact with your REST resource
Object.keys(actions) == ['runUser', 'mergeUsers'];
  • And have the following state by default:

state ==
  {
    isRunning: false,
    isMerging: false
  };

Last updated