0
我正在使用React Reselec t,我試圖篩選selectedClients,使得我只返回來自selectedClientsIds的id的clients.all。使用React Reselect篩選2個陣列
selected_clients.js
import _ from 'lodash';
import { createSelector } from 'reselect';
const clientSelector = state => state.clients.all
const selectedClientSelector = state => state.selectedClientIds
const getClients = (all, selectedClientIds) => {
const selectedClients = _.filter(
all,
client => _.contains(selectedClientIds, all.id)
);
return selectedClients;
};
export default createSelector(
clientSelector,
selectedClientSelector,
getClients
);
的clients.all店看起來是這樣的:
[
{
"id": 1,
"name": 「Bob」,
},
{
"id": 2,
"name": 「Mary 」,
}
]
的selectedClientIds店看起來是這樣的:
[1]
我將如何結合兩者只顯示來自selectedClientId's的id的客戶列表?隨着過濾器我有以上,我不斷收到一個空數組
[]