JavaScript · 662 bytes Raw Blame History
1 import React from 'react';
2 import { detectLocation } from '../services/locationService';
3
4 const LocationDetector = ({ onLocationDetected, setLoading, setError }) => {
5 const handleDetectLocation = async () => {
6 setLoading(true);
7 setError(null);
8
9 try {
10 const location = await detectLocation();
11 onLocationDetected(location);
12 } catch (error) {
13 setError("Couldn't detect your location. Try entering it manually!");
14 } finally {
15 setLoading(false);
16 }
17 };
18
19 return (
20 <button onClick={handleDetectLocation} className="primary-button">
21 Roast Me! 🔥
22 </button>
23 );
24 };
25
26 export default LocationDetector;