Sign in
Log inSign up

Redux API Saga - React API calls made simple

Arun Kumar T K's photo
Arun Kumar T K
·Feb 7, 2019

Takes in a config and gives you a ready to use reducer saga and a common action. Avoid writing unnecessary boilerplate code. Github -> redux-api-saga

Example code which makes an API call to localhost:3001/puppyJpg/20345?resolution=HD

config --->

[{
    path: 'localhost:3001/puppyJpg/:imageId',
    method: 'GET',
    name: 'puppyJpg',
    mode: 'takeLatest',
    initialResult: '',
}]

Usage --->

this.props.dispatch(action({
  name: 'puppyJpg',
  payload: {},
  params: { imageId: 20345 },
  query: { resolution: 'HD' },
  onSuccess: () => {},
  onError: (error) => {
    console.error(typeof error === 'string' ? error : error.message);
  };
}));
Hassle-free blogging platform that developers and teams love.
  • Docs by Hashnode
    New
  • Blogs
  • AI Markdown Editor
  • GraphQL APIs
  • Open source Starter-kit

© Hashnode 2024 — LinearBytes Inc.

Privacy PolicyTermsCode of Conduct