gpt-3.5-turbo-0613· OpenAI
Arena Human Preference 55K
Provide code for a weather component written in react native and typescript.
- User
Provide code for a weather component written in react native and typescript.
- Assistant
Sure! Here's an example of a weather component written in React Native using TypeScript:
import React, { useEffect, useState } from 'react'; import { View, Text, StyleSheet } from 'react-native'; interface Weather { temperature: number; weatherCondition: string; loading: boolean; } const WeatherComponent: React.FC = () => { const [weather, setWeather] = useState<Weather>({ temperature: 0, weatherCondition: '', loading: true, }); useEffect(() => { fetchWeatherData(); }, []); const fetchWeatherData = async () => { try { const response = await fetch('API_URL'); const data = await response.json(); setWeather({ temperature: data.main.temp, weatherCondition: data.weather[0].main, loading: false, }); } catch (error) { console.error('Error fetching weather data:', error); } }; if (weather.loading) { return ( <View style={styles.container}> <Text>Loading...</Text> </View> ); } return ( <View style={styles.container}> <Text>Temperature: {weather.temperature}°C</Text> <Text>Condition: {weather.weatherCondition}</Text> </View> ); }; const styles = StyleSheet.create({ container: { flex: 1, alignItems: 'center', justifyContent: 'center', }, }); export default WeatherComponent;
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.