Skip to content

avoid mutating state #129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/DatePicker.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export default class DatePicker extends React.Component<Props, State> {
}

onDaySelected = (position: number) => {
let selectedDate = this.state.selectedDate
let selectedDate = new Date(this.state.selectedDate.getTime())
const daysAfterSelectedDate = this.state.daysAfterSelectedDate
const hours = selectedDate.getHours()
const minutes = selectedDate.getMinutes()
Expand Down Expand Up @@ -173,7 +173,7 @@ export default class DatePicker extends React.Component<Props, State> {
}

onHourSelected = (position: number) => {
const selectedDate = this.state.selectedDate
const selectedDate = new Date(this.state.selectedDate.getTime())
const { hours, format24 } = this.props
const data = hours || getHoursArray(format24)
if (this.props.format24) {
Expand All @@ -188,15 +188,15 @@ export default class DatePicker extends React.Component<Props, State> {
}

onMinuteSelected = (position: number) => {
const selectedDate = this.state.selectedDate
const selectedDate = new Date(this.state.selectedDate.getTime())
const { minutes } = this.props
const data = minutes || getFiveMinutesArray()
selectedDate.setMinutes(Number(data[position]))
this.onDateSelected(selectedDate)
}

onAmSelected = (position: number) => {
const selectedDate = this.state.selectedDate
const selectedDate = new Date(this.state.selectedDate.getTime())
const time12format = hourTo12Format(selectedDate.getHours())
const newTime12Format = `${time12format[0]} ${getAmArray()[position]}`
const selectedHour24format = hourTo24Format(newTime12Format)
Expand Down