Challenge - 5 Problems
Expo Modules Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
Using Expo Camera Module to Capture a Photo
What will happen when the user taps the button in this React Native Expo app code?
React Native
import React, { useState, useRef } from 'react'; import { View, Button, Image } from 'react-native'; import { Camera } from 'expo-camera'; export default function App() { const [hasPermission, setHasPermission] = useState(null); const [photoUri, setPhotoUri] = useState(null); const cameraRef = useRef(null); React.useEffect(() => { (async () => { const { status } = await Camera.requestCameraPermissionsAsync(); setHasPermission(status === 'granted'); })(); }, []); const takePicture = async () => { if (cameraRef.current) { const photo = await cameraRef.current.takePictureAsync(); setPhotoUri(photo.uri); } }; if (hasPermission === null) { return <View />; } if (hasPermission === false) { return <View><Button title="No access to camera" disabled /></View>; } return ( <View style={{ flex: 1 }}> <Camera style={{ flex: 1 }} ref={cameraRef} /> <Button title="Take Photo" onPress={takePicture} /> {photoUri && <Image source={{ uri: photoUri }} style={{ flex: 1 }} />} </View> ); }
Attempts:
2 left
💡 Hint
Look at how the Camera permission is requested and how the takePicture function is used.
✗ Incorrect
The code requests camera permission on mount, shows the camera preview if granted, and the button triggers takePicture which captures a photo and sets its URI to display the image.
❓ lifecycle
intermediate2:00remaining
Effect of useEffect Dependency on Expo Location Module
Consider this React Native Expo code snippet using the Location module. What will happen if the dependency array in useEffect is empty versus if it includes a state variable 'tracking'?
React Native
import React, { useState, useEffect } from 'react'; import { View, Text, Button } from 'react-native'; import * as Location from 'expo-location'; export default function App() { const [location, setLocation] = useState(null); const [tracking, setTracking] = useState(false); useEffect(() => { let subscriber; if (tracking) { (async () => { const { status } = await Location.requestForegroundPermissionsAsync(); if (status === 'granted') { subscriber = await Location.watchPositionAsync({ accuracy: Location.Accuracy.High }, loc => { setLocation(loc); }); } })(); } else if (subscriber) { subscriber.remove(); } return () => subscriber?.remove(); }, [tracking]); return ( <View> <Button title={tracking ? 'Stop Tracking' : 'Start Tracking'} onPress={() => setTracking(!tracking)} /> <Text>{location ? JSON.stringify(location.coords) : 'No location'}</Text> </View> ); }
Attempts:
2 left
💡 Hint
Think about when useEffect runs based on its dependency array.
✗ Incorrect
useEffect runs only once if dependency array is empty, so changes to 'tracking' won't trigger starting or stopping location updates. Including 'tracking' makes it respond to changes properly.
📝 Syntax
advanced2:00remaining
Correct Import and Usage of Expo Notifications Module
Which option correctly imports and schedules a local notification using Expo Notifications in a React Native app?
Attempts:
2 left
💡 Hint
Check the official Expo Notifications API for method names and import style.
✗ Incorrect
The correct import is 'import * as Notifications from "expo-notifications";' and the method to schedule is 'scheduleNotificationAsync'. Other options use wrong method names or import styles.
🔧 Debug
advanced2:00remaining
Debugging Expo Audio Playback Issue
Given this code snippet using Expo Audio module, the sound does not play when the button is pressed. What is the most likely cause?
React Native
import React, { useState } from 'react'; import { View, Button } from 'react-native'; import { Audio } from 'expo-av'; export default function App() { const [sound, setSound] = useState(); async function playSound() { const { sound: newSound } = await Audio.Sound.createAsync( require('./assets/sound.mp3') ); setSound(newSound); await newSound.playAsync(); } return ( <View> <Button title="Play Sound" onPress={playSound} /> </View> ); }
Attempts:
2 left
💡 Hint
Look carefully at variable names and state usage inside the async function.
✗ Incorrect
Inside playSound, the 'sound' variable declared with const shadows the state variable 'sound'. This can cause confusion but does not prevent playback. However, the code actually works. The real issue is that the sound object is not unloaded on unmount, but that does not stop playback. The most likely cause is the shadowing causing confusion in managing the sound object lifecycle.
🧠 Conceptual
expert2:00remaining
Understanding Expo Module Linking and Bare Workflow
Which statement best describes the difference in using Expo modules in Managed workflow versus Bare workflow in React Native?
Attempts:
2 left
💡 Hint
Think about how Expo handles native code in Managed vs Bare workflows.
✗ Incorrect
Managed workflow abstracts native code setup and pre-links Expo modules. Bare workflow requires manual installation, linking, and native project configuration for Expo modules.