score:2

Accepted answer

you can pass the argument postid as the first argument:

//pass in postid and return a selector function
export const makeselectsublivestreamviews = (postid) => createselector(
  [selectsublivestream],
  (sublivestream) => sublivestream[postid]?.views || 0
);

in your component:

//you need to recreate the selector function when postid chages
//  or you'll get the wrong data
const selectsublivestreamviews = usememo(
  ()=>makeselectsublivestreamviews(postid), [postid]
);
//no need to pass postid again, code looks a little cleaner
const views = useselector(selectsublivestreamviews);

here are some examples how i use reselect with react-redux.


Related Query

More Query from same tag