Rohit Karthik
Rohit Karthik

Reputation: 61

ReferenceError: Can't find variable: False - React Native (Hookstate)

In my React Native code, I've been using Hookstate as my state manager (in this case to see if the user is signed in or not). While my auth flow does show the home page for a second after tapping the log in button, an error then pops up (as shown in the title).

Below is my implementation for the Hookstate state:

import { createState, useState } from "@hookstate/core"

const globalIsLoggedIn = createState(false)

export function useGlobalIsLoggedIn(){
    const state = useState(globalIsLoggedIn)

    return ({
        get isLoggedInVal(){
            return state.value
        },
        setTrue(){
            state.set(true)
        },
        setFalse(){
            state.set(false)
        }
    })
}

export function accessGlobalIsLoggedIn(){
    return ({
        setTrue(){
            globalIsLoggedIn.set(true)
        },
        setFalse(){
            globalIsLoggedIn.set(false)
        }
    })
}

And below is my implementation for App.js:

import React from 'react';
import { SignUpScreen } from './src/SignUpScreen/signUp.js'
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import { LoginScreen } from './src/LoginScreen/login.js';
import { useGlobalIsLoggedIn, useGlobalState } from './src/loggedIn.js';
import { HomeScreen } from './src/HomeScreen/HomeScreen'

const Stack = createStackNavigator();


export default function App() {

  const isLoggedIn = useGlobalIsLoggedIn()

  return (
    <NavigationContainer>
      <Stack.Navigator headerMode="none">
        {
          isLoggedIn.isLoggedInVal ? (
            <Stack.Screen name="Home" component={HomeScreen} />
          ) : (
            <>
              <Stack.Screen name="SignIn" component={SignUpScreen} />
              <Stack.Screen name="Login" component={LoginScreen} />
            </>
          )
        }
      </Stack.Navigator>
    </NavigationContainer>
  );
}

However, when I run the app and update the global state (which happens in a different file), I see the home page for a second, and then an exception "ReferenceError: Can't find variable: False".

Any help would be appreciated.

Upvotes: 0

Views: 1309

Answers (1)

Andrew
Andrew

Reputation: 2135

Author of Hookstate is here. You have got syntax error in your code somewhere. False (starting with a capital F) is not a variable/value defined in JS, unless you define it yourself somewhere (which would be a bad idea). I do not see where you reference False in your code sample, so search the wider code base.

Upvotes: 1

Related Questions