This app asks for camera permission, shows the camera preview, and has a button to take a picture. When you tap the button, it takes a photo and shows the file path below.
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.