I'm fairly new to Redux and am experiencing some behavior I don't quite understand.
I have another function
nextFiveDaysthat calls the exact same action but this is fired with a button click. When the button is clicked, I do see the action.type isUPDATE_DATEdispatched and the store is updated.In the function
nextFiveDays, the action is dispatched even if theupdateDatefunction is commented out. It seemssetStatestill triggers the action to be dispatched. Why is that?
class SomeComponent {
state = { date: new Date() }
nextFiveDays = () => {
let date = new Date(this.state.date);
date.setDate(date.getDate() + 5);
//updateDate(date); // Redux store action dispatch
this.setState({ date });
};
prevFiveDays = () => {
let date = new Date(this.state.date);
date.setDate(date.getDate() - 5);
//updateDate(date); // Redux store action dispatch
this.setState({ date });
};
render() {
const { date } = this.state
return <SemanticDatepicker
value={new Date(date)}
date={new Date(date)}
onChange={(_, data: any) => {
this.setState({ date: data.value });
updateDate(data.value);
}}
/>
<Button
onClick={this.prevFiveDays}
/>
<Button
onClick={this.nextFiveDays}
/>
}