Only use db functions when components are actually mounted

This commit is contained in:
Julia Friesel
2018-09-11 18:06:19 +02:00
parent 04e43b823d
commit 3e3cef8769
6 changed files with 25 additions and 20 deletions
+4 -2
View File
@@ -1,13 +1,15 @@
import React, { Component } from 'react'
import { CalendarList } from 'react-native-calendars'
import {LocalDate} from 'js-joda'
import { getOrCreateCycleDay, bleedingDaysSortedByDate } from '../db'
import { getOrCreateCycleDay, getBleedingDaysSortedByDate } from '../db'
import cycleModule from '../lib/cycle'
import {shadesOfRed} from '../styles/index'
import styles from '../styles/index'
export default class CalendarView extends Component {
constructor(props) {
const bleedingDaysSortedByDate = getBleedingDaysSortedByDate()
super(props)
const predictedMenses = cycleModule().getPredictedMenses()
this.state = {
@@ -31,7 +33,7 @@ export default class CalendarView extends Component {
}
componentWillUnmount() {
bleedingDaysSortedByDate.removeListener(this.setStateWithCalFormattedDays)
getBleedingDaysSortedByDate().removeListener(this.setStateWithCalFormattedDays)
}
passDateToDayView = (result) => {