# Manage the camera lifecycle in React Native

> Keep one Fabric camera view mounted, coordinate pause and resume with navigation, switch lenses safely, and await native cleanup.

> For AI agents: the complete documentation index is at https://nosmai.com/llms/effects.txt

Product: Nosmai Effects
Group: guide
Source: https://nosmai.com/docs/effects/guides/camera/manage-camera-lifecycle/react-native/

## Prerequisites

- A working [React Native quickstart](/docs/effects/quickstart/react-native/)
- One mounted `NosmaiCameraView`
- An Expo development build or native React Native application, not Expo Go

## Pause and resume the camera

Use the public methods when navigation keeps the screen mounted but hides it:

```tsx
await NosmaiCameraSdk.pauseCamera();
await NosmaiCameraSdk.resumeCamera();
```

Serialize focus events so a late resume cannot run after cleanup begins.

## Switch the camera

Await the result and disable the control while switching:

```tsx
const switched = await NosmaiCameraSdk.switchCamera();
if (!switched) return;
```

A `false` result means a rapid or concurrent request was safely skipped;
operational failures reject with a typed SDK error.

## Clean up before remounting

Unmount the camera view and await cleanup before creating a new owner:

```tsx
await NosmaiCameraSdk.cleanup();
```

Remove SDK event subscriptions in the same route cleanup. Do not mount the next
camera screen until the cleanup Promise settles.

## Verify it worked

Switch lenses, background and foreground the app, then navigate away and back
ten times. The OS camera indicator must turn off after cleanup, listeners must
not duplicate, and one Fabric camera view must own the session.

## Common errors

| Error or symptom | Cause | Fix |
| --- | --- | --- |
| `E_OPERATION_CANCELLED` | Cleanup superseded a queued camera operation | Ignore the stale operation and wait for cleanup before remounting |
| Camera2 device error | Another controller or old view still owns Android camera hardware | Await cleanup and keep one mounted camera view |
| Events fire more than once | Subscriptions survived route teardown | Call `remove()` on every SDK subscription during cleanup |

## Next steps

- [Capture a processed photo in React Native](/docs/effects/guides/output/capture-a-photo/react-native/)
- [Record processed video in React Native](/docs/effects/guides/output/record-video/react-native/)

## References

- [React Native API reference](/docs/effects/reference/api/react-native/)
- [React Native package](https://www.npmjs.com/package/@nosmai/react-native-effects-sdk)
