I try to conditionally concat in my reducer, I have an array objects and I want to concatenate only if value not exist in my reducer.
If value exists nothing must happen.
I use lodash and I tried with _.uniqBy
like this :
_.uniqBy(arr1.concat(val1), 'id');
This does not work.
Example of my reducer
const arr1 = [{id:1, name:'alex'}, {id:2, name:'taylor'}]
const val1 = {id:1, name:'alex'};
const reducer = {
finalArr: arr1.concat(val1)
}
console.log('Reducer', reducer)
Required output :
[{id:1, name:'alex'}, {id:2, name:'taylor'}]
Because val1 ({id:1, name:'alex'}) already exists in the array.