@gbgplc-internal/ggo-native-bridge-react in React applications.
Setup
Wrap your app (or the relevant subtree) with<BridgeProvider>:
NativeBridge singleton, auto-detects the host environment, discovers capabilities on mount, and makes the bridge available to all child components via context.
useBridge() — Access the bridge
useBridge() is the main hook for reading bridge state and reaching the underlying NativeBridge instance. It returns the environment, capability map, and helpers for capability checks:
Error if used outside a <BridgeProvider>.
Waiting for capabilities
useCapability(id) — Check a capability
Reactively check whether a specific capability is supported:
useNativeCamera(type) — Camera capture
useNativeCamera() is a convenience hook that wraps the most common bridge request — a document or selfie capture — with the right capability check, action string, and timeout. It returns a flag for whether a native capture is available and a requestCapture() function you call when the user triggers capture:
Camera type mapping
Eachtype value maps to a specific bridge capability and capture action:
useNativeCamera works even without a <BridgeProvider>, returning isNativeAvailable: false. This makes it safe to use in components that may or may not have bridge access.
useBridgeEvent(action, callback) — Listen for host events
- Subscribes on mount, unsubscribes on unmount
- You do not need to wrap the callback in
useCallback— the hook uses a ref internally - Resubscribes only if the
actionstring changes
Emitting events
Combining hooks
Testing
Use theenvironment and channel options to mock the bridge in tests: