donni106 / matomo-tracker-react-native

Stand alone library for using Matomo tracking in React Native and Expo projects.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Invalid hook call after installing package

georgibakken opened this issue · comments

Describe the bug
After installing the package and implemented the basic usage as described in the readme, and running my application in the iOS simulator with expo, I get the following error

Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:95:4 in reportException
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:141:19 in handleException
at node_modules/react-native/Libraries/Core/setUpErrorHandling.js:24:6 in handleError
at node_modules/@react-native/polyfills/error-guard.js:49:36 in ErrorUtils.reportFatalError
at node_modules/metro-runtime/src/polyfills/require.js:203:6 in guardedLoadModule
at http://127.0.0.1:19000/index.bundle?platform=ios&dev=true&hot=false&strict=false&minify=false:253294:3 in global code

Invariant Violation: "main" has not been registered. This can happen if:
* Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
* A module failed to load due to an error and `AppRegistry.registerComponent` wasn't called.
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:95:4 in reportException
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:141:19 in handleException
at node_modules/react-native/Libraries/Core/setUpErrorHandling.js:24:6 in handleError
at node_modules/@react-native/polyfills/error-guard.js:49:36 in ErrorUtils.reportFatalError

Also experienced in Expo's dev client mode.

Affected code lines if helpful Where is the problem?
It's hard to tell. The error only seem to go away after uninstalling the package again.

To Reproduce
Install the latest package, using Expo SDK 45.
Run it in the simulator

Expected behavior
Initialised Matomo where I could track events

Seems like I was using it wrong in regards to const { trackScreenView } = useMatomo();

All right, thanks for reaching out and making it clear.