Skip to content

I cannot load the useAppState hook in my code #28

Closed
@vongohren

Description

@vongohren

Bug

For some reason I get this error when just calling useAppState in my function, that already has many other hooks

Screenshot_20190818-102747

This is the code that runs it, its a child component somewhere, but it runs the code without the useAppState() line. I even added a copy of useAppState in my utils folder and it works.

import React, { useEffect, useState } from 'react';
import { useAppState } from 'react-native-hooks';
import PhoneStatus from '../../containers/phone-status';
import AuthService from '../../services/auth';

import WithoutWallet from './without-wallet';


const onAppFocusChanges = ({ linkingInitialized, setLinkingInitialized }) => {
  if (linkingInitialized) {
    setTimeout(() => {
      setLinkingInitialized(false);
    }, 10000);
  }
};


export default () => {
  const currentAppState = useAppState();
  const [linkingInitialized, setLinkingInitialized] = useState(false);
  
  const phoneStatus = PhoneStatus.useContainer();
  const authService = AuthService.useContainer();

  const { hasWallet } = phoneStatus;
  const { currentUser } = authService;


  useEffect(() => {
    phoneStatus.checkForWallet();
  }, []);


  console.log(hasWallet);

  if (hasWallet) {
    return <WithoutWallet />;
  }
  return <></>;
};

Does this maybe have to do that the react dependency is not a peer dependency stated here: https://reactjs.org/warnings/invalid-hook-call-warning.html#duplicate-react

Environment info

React native info output:

info
  React Native Environment Info:
    System:
      OS: macOS 10.14.6
      CPU: (8) x64 Intel(R) Core(TM) i7-7920HQ CPU @ 3.10GHz
      Memory: 310.77 MB / 16.00 GB
      Shell: 5.3 - /bin/zsh
    Binaries:
      Node: 9.10.0 - ~/.nvm/versions/node/v9.10.0/bin/node
      Yarn: 1.15.2 - ~/.yarn/bin/yarn
      npm: 6.4.0 - ~/.nvm/versions/node/v9.10.0/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 12.4, macOS 10.14, tvOS 12.4, watchOS 5.3
      Android SDK:
        API Levels: 23, 25, 26, 27, 28
        Build Tools: 23.0.1, 26.0.2, 27.0.3, 28.0.0, 28.0.3
        System Images: android-28 | Google Play Intel x86 Atom
    IDEs:
      Android Studio: 3.1 AI-173.4819257
      Xcode: 10.3/10G8 - /usr/bin/xcodebuild

Version number: "react-native": "^0.59.3"
Which resolves now to "0.59.10"

Describe what you expected to happen:

  1. Expected it not to crash

Reproducible sample code

All the stuff inside that code example is non relateable. And as stated, i copied the code and added a utils/hooks/useAppState and that worked fine. So there is something with loading this lib in.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions