question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

useLastNotificationResponse returns null after clicking on a notification

See original GitHub issue

Summary

When testing the useLastNotificationResponse, it returns null even when clicking on a notification when testing it using the Expo Go app. Same bug has been observed in production.

If the app is open, the useLastNotificationResponse hook correctly picks up the notification details when it is tapped on.

Managed or bare workflow? If you have ios/ or android/ directories in your project, the answer is bare!

managed

What platform(s) does this occur on?

Android

SDK Version (managed workflow only)

40

Environment

Expo CLI 4.4.3 environment info: System: OS: macOS 10.15.7 Shell: 5.7.1 - /bin/zsh Binaries: Node: 14.6.0 - /usr/local/bin/node npm: 6.14.13 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman Managers: CocoaPods: 1.10.1 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: iOS 14.4, DriverKit 20.2, macOS 11.1, tvOS 14.3, watchOS 7.2 IDEs: Android Studio: 4.0 AI-193.6911.18.40.6626763 Xcode: 12.4/12D4e - /usr/bin/xcodebuild npmPackages: @expo/webpack-config: ~0.12.45 => 0.12.68 expo: ^40.0.0 => 40.0.1 react: 16.13.1 => 16.13.1 react-dom: 16.13.1 => 16.13.1 react-native: https://github.com/expo/react-native/archive/sdk-40.0.1.tar.gz => 0.63.2 react-native-web: ~0.13.12 => 0.13.18 react-navigation: ^4.4.1 => 4.4.4 npmGlobalPackages: expo-cli: 4.4.3 Expo Workflow: managed

Reproducible demo or steps to reproduce from a blank project

  1. expo init my-project
  2. expo install expo-notifications
  3. Go to app.js and paste in the below
  4. Open the app with a physical device through the Expo Go app
  5. Close the opened app to make sure it is killed
  6. Send notification to the physical device Expo Token and click on it
  7. The app opens but the below console.log(useLastNotificationResponse) shows up as first undefined and then null
import { StatusBar } from "expo-status-bar";
import React from "react";
import { StyleSheet, Text, View } from "react-native";
import * as Notifications from "expo-notifications";

export default function App() {
  const lastNotificationResponse = Notifications.useLastNotificationResponse();

  console.log(lastNotificationResponse);
  return (
    <View style={styles.container}>
      <Text>Open up App.js to start working on your app!</Text>
      <StatusBar style="auto" />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: "#fff",
    alignItems: "center",
    justifyContent: "center",
  },
});


Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
AsserHamadcommented, Oct 19, 2021

I’m on SDK 41 and the problem still persists. As stated above, when the app is closed the notification is undefined then null, however, if the app is in the background then it correctly picks up the notification.

1reaction
cruzachcommented, May 10, 2021

This was fixed in SDK 41 - https://github.com/expo/expo/issues/11933

Read more comments on GitHub >

github_iconTop Results From Across the Web

Expo notification doesnt fire method when app is killed/closed
The problem is that the useEffect() get called too late after the app has finished initializing. Therefore the listener is not added before ......
Read more >
Notifications - Expo Documentation
useLastNotificationResponse (): undefined | NotificationResponse | null. A React hook always returning the notification response that was received most recently ...
Read more >
expo-notifications-bux-fix v0.12.0 - npm.io
useLastNotificationResponse (): undefined | NotificationResponse | null. A React hook always returning the notification response that was received most recently ...
Read more >
How to handle notifications when the app is backgrounded ...
I am using expo-notifications with a managed workflow. When ... the value I get from useLastNotificationResponse is always null when Expo is ......
Read more >
Notifications in Expo & React Native | November 2021
Pusher is already trusted to do so by thousands of developers and companies like GitHub, MailChimp, the Financial Times, Buffer and many ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found