Remove listener when component unmounts
This commit is contained in:
@@ -11,7 +11,6 @@ import { saveBleeding } from './db'
|
|||||||
import { formatDateForViewHeader } from './format'
|
import { formatDateForViewHeader } from './format'
|
||||||
import { bleeding as labels } from './labels'
|
import { bleeding as labels } from './labels'
|
||||||
import getCycleDay from './get-cycle-day'
|
import getCycleDay from './get-cycle-day'
|
||||||
import { bleedingDaysSortedByDate } from './db'
|
|
||||||
|
|
||||||
export default class Bleeding extends Component {
|
export default class Bleeding extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
|
|||||||
+9
-4
@@ -9,10 +9,11 @@ export default class DatePickView extends Component {
|
|||||||
super(props)
|
super(props)
|
||||||
this.state = { bleedingDaysInCalFormat: getBleedingDaysInCalFormat(bleedingDaysSortedByDate) }
|
this.state = { bleedingDaysInCalFormat: getBleedingDaysInCalFormat(bleedingDaysSortedByDate) }
|
||||||
|
|
||||||
// so we rerender the calendar when there are new bleeding days
|
bleedingDaysSortedByDate.addListener(setStateWithCalendarFormattedDays.bind(this))
|
||||||
bleedingDaysSortedByDate.addListener(() => {
|
}
|
||||||
this.setState({ bleedingDaysInCalFormat: getBleedingDaysInCalFormat(bleedingDaysSortedByDate) })
|
|
||||||
})
|
componentWillUnmount() {
|
||||||
|
bleedingDaysSortedByDate.removeListener(setStateWithCalendarFormattedDays)
|
||||||
}
|
}
|
||||||
|
|
||||||
passDateToDayView(result) {
|
passDateToDayView(result) {
|
||||||
@@ -43,4 +44,8 @@ function getBleedingDaysInCalFormat(bleedingDaysSortedByDate) {
|
|||||||
acc[dateString] = { startingDay: true, endingDay: true, color: shadesOfRed[day.bleeding.value] }
|
acc[dateString] = { startingDay: true, endingDay: true, color: shadesOfRed[day.bleeding.value] }
|
||||||
return acc
|
return acc
|
||||||
}, {})
|
}, {})
|
||||||
|
}
|
||||||
|
|
||||||
|
function setStateWithCalendarFormattedDays() {
|
||||||
|
this.setState({ bleedingDaysInCalFormat: getBleedingDaysInCalFormat(bleedingDaysSortedByDate) })
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user