expo / router

[ARCHIVE]: Expo Router has moved to expo/expo -- The File-based router for universal React Native apps
https://docs.expo.dev/routing/introduction/
1.36k stars 113 forks source link

useFocusEffect cleanup - This expression is not callable #906

Closed GustavoBonfimS closed 6 months ago

GustavoBonfimS commented 9 months ago

This problem seems to have been fixed in v3 but caused another problem when installing the ExpoHead Pod so I can't update. (SDK 49

image

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch expo-router@2.0.12 for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/expo-router/src/useFocusEffect.tsx b/node_modules/expo-router/src/useFocusEffect.tsx
index 21dfe2c..d1174f1 100644
--- a/node_modules/expo-router/src/useFocusEffect.tsx
+++ b/node_modules/expo-router/src/useFocusEffect.tsx
@@ -92,7 +92,7 @@ export function useFocusEffect(
         return;
       }

-      if (cleanup !== undefined) {
+      if (cleanup !== undefined && typeof cleanup === 'function') {
         cleanup();
       }

@@ -101,7 +101,7 @@ export function useFocusEffect(
     });

     const unsubscribeBlur = navigation.addListener("blur", () => {
-      if (cleanup !== undefined) {
+      if (cleanup !== undefined && typeof cleanup === 'function') {
         cleanup();
       }

@@ -110,7 +110,7 @@ export function useFocusEffect(
     });

     return () => {
-      if (cleanup !== undefined) {
+      if (cleanup !== undefined && typeof cleanup === 'function') {
         cleanup();
       }

This issue body was partially generated by patch-package.

GustavoBonfimS commented 9 months ago

My tsconfig file

{
  "compilerOptions": {
    "baseUrl": "src",
    "paths": {
      "~/*": [
        "*"
      ]
    },
    "strict": false,
    "plugins": [
      {
        "name": "typescript-styled-plugin",
        "lint": {
          "duplicateProperties": "warning",
          "validProperties": [
            "shadow-color",
            "shadow-opacity",
            "shadow-offset",
            "shadow-radius",
            "padding-horizontal",
            "padding-vertical",
            "margin-vertical",
            "margin-horizontal",
            "tint-color",
            "aspect-ratio",
            "elevation"
          ]
        }
      }
    ]
  },
  "extends": "expo/tsconfig.base",
  "exclude": [
    "node_modules",
    "babel.config.js",
    "metro.config.js",
    "dist",
    "web-build",
    "src/pages",
  ],
  "include": [
    "**/*.ts",
    "**/*.tsx",
    ".expo/types/**/*.ts",
    "expo-env.d.ts",
    "jest-setup-js"
  ]
}
EvanBacon commented 6 months ago

This is fixed in Expo Router v3