futurice / pepperoni-app-kit

Pepperoni - React Native App Starter Kit for Android and iOS
http://getpepperoni.com
MIT License
4.63k stars 643 forks source link

can you supply a example with `utils/api` {get} #197

Open jiqimaogou opened 7 years ago

fabriziomoscon commented 7 years ago

I am not sure if this help, but in my app I am using it as follows with "redux-thunk": "~2.2.0"

import {
    get as apiGet,
    patch as apiPatch,
} from '../utils/api'

export function APIfindProfileInfo() {
    return function(dispatch, getState) {
        dispatch(loadProfileStart())
        return apiGet('https://yourdomain/accounts?id=1', false)
            .then(data => {
                if (!data || !data.account_profile) {
                    dispatch(loadAccountProfileFailure(new Error('no account profile returned')))
                    return
                }
                dispatch(loadAccountProfileSuccess(data))
            })
            .catch(err => dispatch(loadAccountProfileFailure(err)) )
    }
}