-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
Argument of type 'void' is not assignable to parameter of type '(state: AppStateStatus) => void' #33151
Comments
It's because you are on react-native 0.64 and not 0.67 where AppState.addEventListener returns something and AppState.removeEventListener() is deprecated, use AppState.removeEventListener("change", handleOnAppStateChange) or update |
How should this work for react-native 0.65 where |
Any updates? |
@editstudio @t42merli did u find any solution? If you check the example in the documentation and modify its useEffect(() => {
const subscription = AppState.addEventListener("change", nextAppState => {
if (
appState.current.match(/inactive|background/) &&
nextAppState === "active"
) {
console.log("App has come to the foreground!");
}
appState.current = nextAppState;
setAppStateVisible(appState.current);
console.log("AppState", appState.current);
});
console.log(typeof subscription.remove); // <--- ERROR!
return () => {
subscription.remove();
};
}, []); you can see
while export interface AppStateStatic {
currentState: AppStateStatus;
/**
* Add a handler to AppState changes by listening to the change event
* type and providing the handler
*/
addEventListener(type: AppStateEvent, listener: (state: AppStateStatus) => void): void;
/**
* Remove a handler by passing the change event type and the handler
*/
removeEventListener(type: AppStateEvent, listener: (state: AppStateStatus) => void): void;
} Wtf? Am I missing something? |
@VictorioMolina The
|
@VictorioMolina I had the exact same issue as you, but then I remembered I also needed to update the react-native typings to the correct version. |
@ernstluring is correct, you also need to update the "devDependencies": {
...
"@types/react-native": "^0.68.2",
} |
Description
I am trying to remove my AppState listener subscription, but I am getting the following es-lint warning:
Argument of type 'void' is not assignable to parameter of type '(state: AppStateStatus) => void'
I am just doing this:
I know that the
removeEventListener
method is deprecated, but the.remove()
is not a method ofunsubAppState
... in fact,AppState.addEventListener
seems to be returningvoid
.Version
0.64.3
Output of
npx react-native info
System:
OS: macOS 10.15.7
CPU: (8) x64 Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz
Memory: 4.65 GB / 16.00 GB
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 16.13.0 - /usr/local/bin/node
Yarn: 1.22.10 - /usr/local/bin/yarn
npm: 8.4.0 - /usr/local/bin/npm
Watchman: 2021.06.07.00 - /usr/local/bin/watchman
Managers:
CocoaPods: Not Found
SDKs:
iOS SDK:
Platforms: iOS 14.4, DriverKit 20.2, macOS 11.1, tvOS 14.3, watchOS 7.2
Android SDK: Not Found
IDEs:
Android Studio: Not Found
Xcode: 12.4/12D4e - /usr/bin/xcodebuild
Languages:
Java: Not Found
npmPackages:
@react-native-community/cli: Not Found
react: ^17.0.2 => 17.0.2
react-native: https://github.com/expo/react-native/archive/sdk-44.0.0.tar.gz => 0.64.3
react-native-macos: Not Found
Steps to reproduce
Snack, code example, screenshot, or link to a repository
No response
The text was updated successfully, but these errors were encountered: