W
W
webe2018-06-29 07:36:57
React
webe, 2018-06-29 07:36:57

How to correctly pass parameters to reselect?

in store such branches:

store: {
    posts: [{ id: '300', name: 'Название поста' }],
    comments: [{ id: '10000', POST_ID: 300, 'title':'Всем привет' }],
  },

There is a container that renders my posts through the map.
I need to show the number of comments next to each post.
In general, I got the following selectors:
export const getAllCommentsSelector = state => state.comments; // берем все комменты
export const getCurrentIDSelector = (state, props) => props.id; //это ID нашей статьи, напомню что вызываем Connect из всех статей
export const getCountByGroupID = createSelector(
  getAllCommentsSelectorSelector,
  getCurrentIDSelector,
  (Comments, ID) => Comments.filter(el => el.POST_ID === ID).length,
); // тут получаем поличество комментариев для статьи

I call these sliders from each post, i.e. 20 connect stabats
1) Tell me, pliz, is this practice normal or not?
Are there any other options?
Getting an ID here is very crutch, as I understand it, I can’t throw more props in any way?
2) Using connect on a post isn't bad practice? in fact, I will have about 100 Connects

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question