What is the purpose of the expo-camera library in React Native?
The expo-camera library allows React Native apps to access and use the device's camera for taking photos and recording videos.
Click to reveal answer
beginner
How do you request permission to use the camera with expo-camera?
You use the Camera.requestCameraPermissionsAsync() method to ask the user for permission to access the camera.
Click to reveal answer
beginner
What React hook is commonly used to manage camera permission state in a functional component?
The useState hook is used to store and update the camera permission status (granted or denied).
Click to reveal answer
intermediate
Why should you check camera permissions before rendering the camera view?
Checking permissions first ensures the app only tries to show the camera if the user has allowed access, preventing errors and improving user experience.
Click to reveal answer
beginner
How do you display the camera preview on screen using expo-camera?
You render the <Camera> component from expo-camera and set its style and type (front or back camera).
Click to reveal answer
Which method requests camera permission in expo-camera?
ACamera.getPermissions()
BPermissions.askCamera()
CCamera.requestCameraPermissionsAsync()
DCamera.enable()
✗ Incorrect
The correct method to request camera permission is Camera.requestCameraPermissionsAsync().
What React hook is best to track if camera permission is granted?
AuseState
BuseContext
CuseRef
DuseEffect
✗ Incorrect
The useState hook is used to store and update permission status.
Which component shows the live camera feed in expo-camera?
A<Camera>
B<CameraFeed>
C<CameraView>
D<CameraPreview>
✗ Incorrect
The <Camera> component displays the live camera preview.
What should you do if camera permission is denied?
AForce camera to open anyway
BShow an error message or alternative UI
CRestart the app
DIgnore and continue
✗ Incorrect
If permission is denied, show a message or alternative UI to inform the user.
Which camera type can you select in expo-camera?
AOnly front camera
BNo camera selection possible
COnly back camera
DFront or back camera
✗ Incorrect
You can choose between front and back cameras using the type prop.
Explain how to request and handle camera permissions using expo-camera in a React Native app.
Think about asking the user first, then showing the camera only if allowed.
You got /4 concepts.
Describe how to display a live camera preview using the expo-camera library.
Focus on the component and props needed for the preview.
You got /4 concepts.
Practice
(1/5)
1. What is the first step to use the camera in a React Native app with expo-camera?
easy
A. Directly show the camera preview
B. Request permission to access the camera
C. Take a picture immediately
D. Install a photo editing library
Solution
Step 1: Understand permission requirement
Mobile apps must ask user permission before accessing hardware like the camera.
Step 2: Request camera permission first
Using expo-camera, you call permission request functions before showing the camera.
Final Answer:
Request permission to access the camera -> Option B
Quick Check:
Permission request = A [OK]
Hint: Always ask permission before using hardware [OK]
Common Mistakes:
Trying to show camera preview without permission
Taking picture before permission granted
Skipping permission request step
2. Which of the following is the correct way to import the Camera component from expo-camera?
easy
A. import Camera from 'expo-camera';
B. import CameraComponent from 'expo-camera';
C. import * as Camera from 'expo-camera';
D. import { Camera } from 'expo-camera';
Solution
Step 1: Check expo-camera export style
The Camera component is a named export, so it must be imported with curly braces.
Step 2: Use correct import syntax
Correct syntax is import { Camera } from 'expo-camera'; to access the Camera component.
Final Answer:
import { Camera } from 'expo-camera'; -> Option D
Quick Check:
Named import uses curly braces = D [OK]
Hint: Named exports need curly braces in import [OK]
Common Mistakes:
Using default import without braces
Importing everything as an object
Using wrong import names
3. What will be the output of this code snippet inside a React Native component using expo-camera?
A. Shows camera preview immediately without permission
B. Shows 'No access' text always
C. Shows 'Requesting permission' text initially, then camera preview if granted
D. Throws a syntax error
Solution
Step 1: Analyze permission state flow
Initially, hasPermission is null, so it shows 'Requesting permission'.
Step 2: After permission request
If permission granted, hasPermission becomes true and camera preview shows; if denied, shows 'No access'.
Final Answer:
Shows 'Requesting permission' text initially, then camera preview if granted -> Option C
Quick Check:
Permission null -> text, granted -> camera = B [OK]
Hint: Check initial state null shows loading text [OK]
Common Mistakes:
Expecting camera preview before permission granted
Confusing permission states
Ignoring async permission request
4. Identify the error in this React Native code snippet using expo-camera:
const cameraRef = React.useRef(null);
async function takePicture() {
if (cameraRef) {
const photo = await cameraRef.current.takePictureAsync();
console.log(photo.uri);
}
}
medium
A. cameraRef should be checked as cameraRef.current, not cameraRef
B. takePictureAsync() is not an async function
C. cameraRef must be a state variable, not a ref
D. console.log cannot print photo.uri
Solution
Step 1: Check cameraRef usage
cameraRef is a ref object; to access the camera instance, use cameraRef.current.
Step 2: Correct condition check
The condition should check if (cameraRef.current) to ensure the camera is ready.
Final Answer:
cameraRef should be checked as cameraRef.current, not cameraRef -> Option A
Quick Check:
Ref object needs .current to access value = C [OK]
Hint: Check .current on refs before use [OK]
Common Mistakes:
Checking ref object directly instead of .current
Forgetting async on takePictureAsync
Misusing console.log for URIs
5. You want to build a React Native app that takes a photo only if the user grants camera permission and then saves the photo URI in state. Which sequence of steps is correct?
hard
A. Request permission -> Show camera preview -> Use ref to take picture -> Save URI in state
B. Show camera preview -> Take picture -> Request permission -> Save URI in state
C. Take picture -> Request permission -> Show camera preview -> Save URI in state
D. Save URI in state -> Request permission -> Show camera preview -> Take picture
Solution
Step 1: Request permission before camera use
Always ask and confirm permission before showing camera preview.
Step 2: Show camera preview and take picture
Use a ref to access the camera and take a picture only after permission granted.
Step 3: Save photo URI in state
Store the photo URI in state to use or display later in the app.
Final Answer:
Request permission -> Show camera preview -> Use ref to take picture -> Save URI in state -> Option A
Quick Check:
Permission first, then camera, then save = A [OK]
Hint: Permission first, then camera, then save URI [OK]
Common Mistakes:
Taking picture before permission
Saving URI before picture taken
Showing camera without permission
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.