Reputation: 749
I am using react-reselect to filter out some data. I have to different arrays of data which I have to check if they are matching or not. How can I do a filter with two different arrays and have to run map function on them
Here is my selector
export const AssignedUserSelector = createSelector(
[EmployeeSelector],
employee => {
const freshData = newData.map(newlyAssign => newlyAssign);
return employee.employees.filter(assign => assign.employeeId === newData);
}
);
here freshdata is something like this ["2222","333", "4444"] and employee.employees is like this [{id:"222", name: "John"}, {id:"333", name: "Jane"}, {id:"5555", name: "Josh"}].
What I am trying to do is filter out employees as per the id received. How I can I achieve this in react.
Upvotes: 0
Views: 3830
Reputation: 2008
Not entirely sure what you're doing with your example code, but this is probably what you're looking for:
Multiple Ids
const employeeIds = ["2222", "333", "4444"];
const employee = {
employees: [{
id: "222",
name: "John"
},{
id: "333",
name: "Jane"
},{
id: "5555",
name: "Josh"
}]
};
employee.employees.filter(({ id }) => !employeeIds.includes(id));
Single Id
const employeeId = "222";
const employee = {
employees: [{
id: "222",
name: "John"
},{
id: "333",
name: "Jane"
},{
id: "5555",
name: "Josh"
}]
};
employee.employees.filter(({ id }) => id !== employeeId);
Upvotes: 2