Skip to content
Snippets Groups Projects
Commit f98a6019 authored by Julia Friesel's avatar Julia Friesel
Browse files

Remove listener on componentUnmount and clean up state

parent a56ee7df
No related branches found
No related tags found
No related merge requests found
...@@ -15,14 +15,20 @@ const getCycleDay = cycleDayModule(bleedingDaysSortedByDate) ...@@ -15,14 +15,20 @@ const getCycleDay = cycleDayModule(bleedingDaysSortedByDate)
export default class DayView extends Component { export default class DayView extends Component {
constructor(props) { constructor(props) {
super(props) super(props)
this.cycleDay = props.navigation.state.params.cycleDay
this.state = { this.state = {
cycleDay: props.navigation.state.params.cycleDay cycleDayNumber: getCycleDay(this.cycleDay.date),
} }
bleedingDaysSortedByDate.addListener(setStateWithCurrentCycleDayNumber.bind(this))
}
componentWillUnmount() {
bleedingDaysSortedByDate.removeListener(setStateWithCurrentCycleDayNumber)
} }
render() { render() {
const navigate = this.props.navigation.navigate const navigate = this.props.navigation.navigate
const day = this.state.cycleDay const day = this.cycleDay
const bleedingValue = day.bleeding && day.bleeding.value const bleedingValue = day.bleeding && day.bleeding.value
let bleedingLabel let bleedingLabel
if (typeof bleedingValue === 'number') { if (typeof bleedingValue === 'number') {
...@@ -43,4 +49,10 @@ export default class DayView extends Component { ...@@ -43,4 +49,10 @@ export default class DayView extends Component {
</View > </View >
) )
} }
}
function setStateWithCurrentCycleDayNumber() {
this.setState({
cycleDayNumber: getCycleDay(this.cycleDay.date)
})
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment