Skip to content
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

Avoid removeEventListener Warning #110

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
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class CountDown extends React.Component {
until: Math.max(this.props.until, 0),
lastUntil: null,
wentBackgroundAt: null,
appStateSubscription: null
Copy link

@miguelzabalaf miguelzabalaf Sep 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Lamonarch87
If you use TypeScript in your project, assign this PropType to appStateSubscription, to avoid warnings when rendering the component:

appStateSubscription: PropTypes.oneOfType([PropTypes.func, PropTypes.object])

};

constructor(props) {
Expand All @@ -51,12 +52,12 @@ class CountDown extends React.Component {
}

componentDidMount() {
AppState.addEventListener('change', this._handleAppStateChange);
this.appStateSubscription = AppState.addEventListener('change', this._handleAppStateChange);
}

componentWillUnmount() {
clearInterval(this.timer);
AppState.removeEventListener('change', this._handleAppStateChange);
this.appStateSubscription.remove();
}

componentDidUpdate(prevProps, prevState) {
Expand Down