Skip to content

Instantly share code, notes, and snippets.

@Colour-Full
Last active March 18, 2018 20:12
Show Gist options
  • Save Colour-Full/8b0d602a7f6e10985adbf9ad553d06b2 to your computer and use it in GitHub Desktop.
Save Colour-Full/8b0d602a7f6e10985adbf9ad553d06b2 to your computer and use it in GitHub Desktop.
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