Skip to content

Instantly share code, notes, and snippets.

@Y-Taras
Last active July 2, 2017 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Y-Taras/ec4003f00bd9452e24e397df314b9f4a to your computer and use it in GitHub Desktop.
Save Y-Taras/ec4003f00bd9452e24e397df314b9f4a to your computer and use it in GitHub Desktop.
import axios from 'axios';
import { SET_FILTER_TERM, SET_FILTER_PRICE, ADD_API_DATA } from './actions';
export function setFilterTerm(filterTerm) {
return { type: SET_FILTER_TERM, payload: filterTerm };
}
export function setFilterPrice(filterPrice) {
return { type: SET_FILTER_PRICE, payload: filterPrice };
}
export function addAPIData(apiData) {
return { type: ADD_API_DATA, payload: apiData };
}
export function getAPIDetails() {
return (dispatch) => {
axios
.get("http://localhost:3000/productsList")
.then(response => {
dispatch(addAPIData(response.data));
})
.catch(error => {
console.error('axios error', error); // eslint-disable-line no-console
});
};
}
import { combineReducers } from 'redux';
import { SET_FILTER_TERM, SET_FILTER_PRICE, ADD_API_DATA } from './actions';
const filterTerm = (state = '', action) => {
if (action.type === SET_FILTER_TERM) {
return action.payload;
}
return state;
};
const filterPrice = (state = {}, action) => {
if (action.type === SET_FILTER_PRICE) {
return action.payload;
}
return state;
};
const apiData = (state = [], action) => {
if (action.type === ADD_API_DATA) {
return action.payload;
}
return state;
};
const rootReducer = combineReducers({ filterTerm, filterPrice, apiData });
export default rootReducer;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment