Skip to content

Commit 8785f1f

Browse files
committed
Avoiding extra setState for setting buttonIcon
1 parent fa5d5fe commit 8785f1f

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/expandableCalendar/calendarProvider.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class CalendarProvider extends Component {
2929
date: this.props.date || XDate().toString('yyyy-MM-dd'),
3030
updateSource: UPDATE_SOURCES.CALENDAR_INIT,
3131
buttonY: new Animated.Value(-65),
32-
buttonIcon: this.getButtonIcon(props.date),
32+
buttonIcon: props.showTodayButton && this.getButtonIcon(props.date),
3333
disabled: false,
3434
opacity: new Animated.Value(1)
3535
};
@@ -45,7 +45,7 @@ class CalendarProvider extends Component {
4545
};
4646

4747
setDate = (date, updateSource) => {
48-
this.setState({date, updateSource}, () => {
48+
this.setState({date, updateSource, buttonIcon: this.props.showTodayButton && this.getButtonIcon(date)}, () => {
4949
this.animateTodayButton(date);
5050
});
5151
_.invoke(this.props, 'onDateChanged', date, updateSource);
@@ -85,7 +85,6 @@ class CalendarProvider extends Component {
8585

8686
animateTodayButton(date) {
8787
if (this.props.showTodayButton) {
88-
this.setState({buttonIcon: this.getButtonIcon(date)});
8988

9089
const today = XDate().toString('yyyy-MM-dd');
9190
const isToday = today === date;

0 commit comments

Comments
 (0)