reactjs - How do I add data from one reducer to existing data in the store? -


when user searches in reactjs app gets results. when user scrolls want load in next set of data in infinite scroll using react-waypoint. works following:

  • loading initial set of items (and showing them)
  • triggering waypoint scroll
  • incrementing page counter on scroll
  • loading next page item api nextitems on scroll

what can't working appending existing items. have seperate reducer loads data nextitems. want add existing items. i've tried following in items.js reducers. add undefined entry nextitems array. somehow can't wrap head around this.

export function items(state = [], action) {     switch (action.type) {         case 'items_fetch_data_success':             return action.items;          default:             return state;     } } export function nextitems(state = [], action) {     switch (action.type) {         case 'items_fetch_next_data_success':             return [...state.items, ...action.nextitems];          default:             return state;     } } 

i have feeling have combine both reducers , split them on type, or fix in item.js actions file. don't know how working, , tried got me either confusing errors, or nothing @ all.

my actions: https://pastebin.com/zepsxhb8

my reducers: https://pastebin.com/dsnffff0

you should able acheive array.prototype.concat.

export function nextitems(state = [], action) {     switch (action.type) {         case 'items_fetch_next_data_success':             return object.assign({},                  state.items,                  state.items.concat(action.nextitems)             );          default:             return state;     } } 

Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -