kimxogus / react-native-version-check

A version checker for react-native applications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot read property 'currentVersion' of null

pk936 opened this issue · comments

  1. Install this library.
  2. Added following code in useEffect
  3. Ran command - npm run android
  4. Console error [TypeError: Cannot read property 'currentVersion' of null]

useEffect(() => {
        checkUpdateNeeded();
    });

const checkUpdateNeeded = async () => {
        try {
            let updateNeeded = await VersionCheck.needUpdate();
            if (updateNeeded.isNeeded) {
                Alert.alert("Please Update",
                    "A new version of the app is available.",
                    [
                        {
                            text: "Update",
                            onPress: () => {
                                BackHandler.exitApp();
                                Linking.openURL(updateNeeded.storeUrl)
                            }
                        }
                    ])
            }
        } catch (error) {

        }
    }

It's fixed.

I ran

  1. react-native link
  2. cd android && ./gradlew clean
  3. npm run android

react-native link not working magically for me. What I did is follow manually linking process. Found under my android folder I did miss set up setting inside android/settings.gradle. Once I added contents inside it, then rebuild android app again, the needUpdate function returned expected response object to me.