In my component, i.e. componentDidMount()
I am subscribing to a state of my rxjs store, which holds an object array workingHours: WorkingHours[]
, that might have items for this month (for example an amount of 8 working hours for the date 27.02-2023 as one item out of 28).
this.context.store.state$
.pipe(map((state) => state.workingHourList[this.props.employeeId] || []))
.subscribe((workingHours) => {
if (workingHours.length > 1) {
this.updateWorkingHours(
workingHours.filter(
(wl) => wl.date.getMonth() === this.props.month.getMonth()
)
);
}
The problem is, that workingHours
in subscribe((workingHours) => { ...
might have zero items, until it finally receives the data from the database. So previously I check, if there are items in workingHours with
if (workingHours.length > 1) {
I don't want to go the bad way of coding and use setTimeout
on a few seconds (which works), so I actually want to check if the workingHours
are the "finalized" workingHours
and there won't come another one.