Skip to content

Commit

Permalink
Fix bug in example of functional component
Browse files Browse the repository at this point in the history
I found out that when _handleAppStateChange is triggered, appState is still "active". Therefore, ```appState.match(/inactive|background/)``` always return null. I believe this because _handleAppStateChange passed to useEffect was not updated. I propose a fix that is to add _handleAppStateChange to dependencies list of useEffect.
  • Loading branch information
ttlong3103 authored Jun 24, 2020
1 parent fb5e953 commit 2962629
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion docs/appstate.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const AppStateExample = () => {
return () => {
AppState.removeEventListener("change", _handleAppStateChange);
};
}, []);
}, [_handleAppStateChange]);
const _handleAppStateChange = (nextAppState) => {
if (appState.current.match(/inactive|background/) && nextAppState === "active") {
Expand Down

0 comments on commit 2962629

Please sign in to comment.