api - Redux - Filterable category with products - Actions & Filter -
my state looks this:
{ categories: { "unique-category-id" { "data": { // kind of data (name, description ,etc ) "products": [ { // products belong category current filter } ] }, "readystate": "category_fetched", "query": { // object holds params filter allows choose "brands": [], "options": { "usb": true "minprice": 200 } } } } }
this works , fetches data correctly. it's time implement filtering funcionality. trying make work this, not sure if "redux" way of doing things.
1.- on each filter on category page assign click handler:
<li onclick={this.togglefilterfield} key={item.value}>{item.name}</li>
togglefilterfield passed container via mapdispatchtoprops:
const mapdispatchtoprops = (dispatch) => { return { togglefilterfield: (category, filter) => { dispatch(togglefilterfield(category, filter)) } } } export { customtagfilter }; export default connect(null, mapdispatchtoprops)(customtagfilter);
2.- tooglefilterfield should return action one:
return { type: change_filter, category, filter }
then category_reducer.js should handle action , update following state key
state.categories[unique-category-id].query
now ok, now, after applying filter state have refetch data category.
how , fire new action based on previous action success?
is correct way of handling filtered elements in redux come paginated api?
Comments
Post a Comment