Last active
March 18, 2018 20:12
-
-
Save Colour-Full/8b0d602a7f6e10985adbf9ad553d06b2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import axios from 'axios'; | |
// Exporting our actions | |
export const LOADING_RECIPES = 'LOADING_RECIPES'; | |
export const GET_RECIPES = 'GET_RECIPES'; | |
// An action to check if the recipes are loaded accepts true or false | |
export function loadingRecipes(loading) { | |
return { | |
type: LOADING_RECIPES, | |
payload: loading, | |
}; | |
} | |
// This will get the recipes from the API | |
export function fetchRecipes(data) { | |
return { | |
type: GET_RECIPES, | |
payload: data, | |
}; | |
} | |
// This is a redux thunk that will fetch our model data | |
export function recipesFetchData(url) { | |
return (dispatch) => { | |
const request = axios.get(url); | |
request.then((response) => { | |
dispatch(loadingRecipes(false)); | |
dispatch(fetchRecipes(response.data.recipe)); | |
}); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment