Skip to content

Commit

Permalink
Adding remove listener to DarkMode HOC
Browse files Browse the repository at this point in the history
  • Loading branch information
etoledom committed Aug 26, 2019
1 parent 8d6942f commit 1380ab6
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/components/src/mobile/dark-mode/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,16 @@ export function withTheme( WrappedComponent ) {
};
}

onModeChanged( newMode ) {
this.setState( { mode: newMode } );
}

componentDidMount() {
eventEmitter.on( 'currentModeChanged', ( newMode ) => {
this.setState( { mode: newMode } );
} );
this.subscription = eventEmitter.on( 'currentModeChanged', this.onModeChanged );
}

componentWillUnmount() {
eventEmitter.removeListener( 'currentModeChanged', this.onModeChanged );
}

render() {
Expand Down

0 comments on commit 1380ab6

Please sign in to comment.