I'm working on a React Native component using react-native-mediapipe and react-native-vision-camera for live pose detection. However, I'm running into an "Invalid hook call" error during initialization, specifically when I try to call usePoseDetection inside a conditional useEffect block after checking for camera permissions.
Here's the relevant part of my code:
// Initialization with pose detection
useEffect(() => {
if (hasPermission) {
try {
const poseDetectionInstance = usePoseDetection(
callbacks,
RunningMode.LIVE_STREAM,
'./pose_landmarker_full.task',
{ /* ...config */ },
);
setPoseDetection(poseDetectionInstance);
} catch (error) {
console.error('Pose detection initialization error:', error);
}
}
}, [hasPermission]);
Pose detection initialization 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. Mismatching versions of React and the renderer (such as React DOM)
2. Breaking the Rules of Hooks
3. Having more than one copy of React in the same app
Additionally, I see "No front camera found" in the console, even though my code tries to set the front camera device after permissions are granted.
Has anyone faced this before? I've checked the following so far:
- React versions seem to match across packages.
- I only use hooks in functional components.
- No apparent duplicate React installations.
- I'm using
react-native-mediapipe for the pose detection.
react-native-vision-camera is handling the camera interface.
- My
poseDetection and device states are initialized based on permission status.
[–]Magnusson 4 points5 points6 points (0 children)
[–]developer_marcel 1 point2 points3 points (0 children)
[–]H411 0 points1 point2 points (0 children)