javascript - React filtering action not working -


given currentuser id, , database of 'events' created various users, trying fetch filtered list of events include events created current user, in other words, events.

my plan of attack make piece of state 'filter' updated depending on various things, right having trouble getting basic filter work.

the error occurs within function below paragraph. have gotten error staying "currentuser" undefined, or "author_id" undefined or "cannot read property author_id or undefined."

currentuser defined on store when checked getstate.

filtermyevents() {     let cid = currentuser.id     let e = this.props.events     let myeventsfilter = (events, id) => {       debugger       (cid === e[id].author_id)     }     myeventsfilter = myeventsfilter.bind(null, this.props.events)     this.props.updatefilter(myeventsfilter);   } 

the filtering takes place in selector.js

export const alleventsbyfilter = (events, filter) => { if (filter) {   return object.keys(events).filter(filter); } else {   return events; } } 

user container:

const mapstatetoprops = (state) => ({   currentuser: state.session.currentuser,   requestevents: requestevents,   events: alleventsbyfilter(state.events, state.filter) });  const mapdispatchtoprops = (dispatch) => ({   requestevents: () => { dispatch(requestevents()) },   updatefilter: (filter) => dispatch(updatefilter(filter)) }) 

filter actions:

export const filterconstants = {   update_filter: "update_filter" };  export const updatefilter = (filter) => ({   type: filterconstants.update_filter,   filter }); 

filters reducer

const _defaultfilters = () => {     return true; }   const filtersreducer = function(state = null, action){   if (action.type === filterconstants.update_filter){     // const newfilter = {[action.filter]: action.value};     return action.filter;   } else {     return state;   } }; 


Comments