O'Reilly logo

React Native Cookbook by Crysfel Villa, Stan Bershadskiy

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Communicating with a Remote API

We are currently loading the bookmarks from hardcoded data in the action; ideally, we should make a request to an API to get the existing bookmarks.

In this recipe, we will create a middleware to fetch data from an API; we will create a common code base to handle all the requests and automatically dispatch actions when the request successfully completes or fails.

How to do it...

  1. We will start by defining the action creator. Let's open the src/redux/modules/categories/actions.js file and add the following action types:
            export const LOAD_CATEGORIES = 'categ/LOAD_CATEGORIES';        export const LOAD_CATEGORIES_SUCCESS = 'categ/LOAD_CATEGORIES_S';        export const LOAD_CATEGORIES_FAIL = 'categ/LOAD_CATEGORIES_F'; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required