Vadim Fisher
Vadim Fisher

Reputation: 27

Redux change state object property based on another changed parameter

I want to change the startDate and finishDate properties of my state object at the same time. The problem is that a new finishDate should be based on new startDate value but it seems because of the startDate not updated yet at the time of reducer's work the finishDate points to the previous state. What is the best way to solve that?

{
...state,
startDate: new Date(newStartDate),
finishDate: new Date(startDate).setHours(...)
}

Upvotes: 0

Views: 78

Answers (1)

Romesh Kosme
Romesh Kosme

Reputation: 26

This should work

{
...state,
startDate: new Date(newStartDate),
finishDate: new Date(new Date(newStartDate)).setHours(...)
}

Upvotes: 1

Related Questions