Last active
July 2, 2017 21:20
-
-
Save Y-Taras/ec4003f00bd9452e24e397df314b9f4a to your computer and use it in GitHub Desktop.
This file contains 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'; | |
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 | |
}); | |
}; | |
} |
This file contains 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 { 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