I have seasons object and selectedSeasonIds
which holds data whether selected key is selected or not.
I'm refactoring the array to object data structure for better performance.
I want to render ONLY selected season while I have these data
seasons = {30: 'Fall', 31: 'Spring', 32: 'All'}
selectedSeasonIds = {30: true, 31: false, 32: true}
let output = selectedSeasonIds.????
// {30: 'Fall', 32: 'All'} <- This is my goal
I used the selector to select the selected objects. But I don't see any benefit of using it.Please feel free to use my code or create better one. Here is my snippet of my code
Here is my selector.
const getSeasons = (seasons, selectedSeasonIds) => {
const selectedSeasons = _.filter(
seasons,
season => _.includes(selectedSeasonIds, season.id)
);
return selectedSeasons;
}
I'm getting selected objects from selector
selectedSeasons = SelectedSeasonsSelector(this.state) << getting selector
if(selectedSeasons.length==0) {
return '-'
}
let seasonList = selectedSeasons.map((season) => {
return ' '+season.value;
})
return seasonList
Thanks!!!