ν°μ€ν 리 λ·°
π [2νΈ] μ±λ΄ UI ꡬμ±νκΈ° – μ¬μ©μ μ λ ₯κ³Ό GPT μλ΅μ μ°κ²°νμ
octo54 2025. 5. 30. 14:54π [2νΈ] μ±λ΄ UI ꡬμ±νκΈ° – μ¬μ©μ μ λ ₯κ³Ό GPT μλ΅μ μ°κ²°νμ
μ΄λ² νΈμμλ μ¬μ©μ μ
λ ₯μ°½κ³Ό GPTμ μλ΅μ 보μ¬μ£Όλ κΈ°λ³Έ μ±λ΄ UIλ₯Ό λ§λ€μ΄λ΄
λλ€.
μ€μ λ‘ μ¬μ©μκ° λ¬Έμ₯μ μ
λ ₯νκ³ → GPTλ‘λΆν° μλ΅μ λ°μ → νλ©΄μ νμνλ
μ± μΈν°νμ΄μ€μ 첫 λ¨κ³λ₯Ό ꡬννλ κ²μ΄ λͺ©νμ
λλ€.
π― λͺ©ν
β
μ¬μ©μ μ
λ ₯μ°½ ꡬν
β
λ©μμ§ μ μ‘ λ²νΌ
β
GPT μλ΅ λ°μ νλ©΄μ μΆλ ₯
β
λ©μμ§ λ¦¬μ€νΈ κ΄λ¦¬ (μ±ν
μ²λΌ 보μ΄κ²)
π§± νλ‘μ νΈ κ΅¬μ‘°
src/
βββ components/
β βββ ChatMessage.js # λ§νμ μ»΄ν¬λνΈ
βββ screens/
β βββ ChatScreen.js # μ 체 μ±ν
νλ©΄
βββ services/
β βββ chatgpt.js # GPT API μμ²
App.js
π§π» 1. GPT μλ΅ ν¨μ (볡μ΅)
π src/services/chatgpt.js
import axios from 'axios';
import { OPENAI_API_KEY } from '@env';
export const askGPT = async (message) => {
const res = await axios.post(
'https://api.openai.com/v1/chat/completions',
{
model: 'gpt-4',
messages: [{ role: 'user', content: message }],
},
{
headers: {
'Authorization': `Bearer ${OPENAI_API_KEY}`,
'Content-Type': 'application/json',
}
}
);
return res.data.choices[0].message.content;
};
π¬ 2. λ§νμ μ»΄ν¬λνΈ
π src/components/ChatMessage.js
import { View, Text, StyleSheet } from 'react-native';
export default function ChatMessage({ message, isUser }) {
return (
<View style={[styles.container, isUser ? styles.user : styles.bot]}>
<Text style={styles.text}>{message}</Text>
</View>
);
}
const styles = StyleSheet.create({
container: {
maxWidth: '80%',
marginVertical: 4,
padding: 10,
borderRadius: 10,
},
user: {
alignSelf: 'flex-end',
backgroundColor: '#007aff',
},
bot: {
alignSelf: 'flex-start',
backgroundColor: '#e5e5ea',
},
text: {
color: '#fff',
},
});
π₯οΈ 3. μ 체 μ±ν νλ©΄ ꡬμ±
π src/screens/ChatScreen.js
import React, { useState } from 'react';
import { View, TextInput, Button, FlatList, KeyboardAvoidingView, Platform } from 'react-native';
import ChatMessage from '../components/ChatMessage';
import { askGPT } from '../services/chatgpt';
export default function ChatScreen() {
const [input, setInput] = useState('');
const [messages, setMessages] = useState([]);
const sendMessage = async () => {
if (!input.trim()) return;
const userMessage = { text: input, isUser: true };
setMessages(prev => [...prev, userMessage]);
setInput('');
try {
const gptReply = await askGPT(input);
const botMessage = { text: gptReply, isUser: false };
setMessages(prev => [...prev, botMessage]);
} catch (error) {
console.error('GPT μλ΅ μ€ν¨:', error);
}
};
return (
<KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'padding' : undefined} style={{ flex: 1 }}>
<FlatList
data={messages}
keyExtractor={(item, index) => index.toString()}
renderItem={({ item }) => <ChatMessage message={item.text} isUser={item.isUser} />}
contentContainerStyle={{ padding: 16 }}
/>
<View style={{ flexDirection: 'row', padding: 8 }}>
<TextInput
style={{ flex: 1, borderWidth: 1, borderColor: '#ccc', padding: 8, borderRadius: 5 }}
value={input}
onChangeText={setInput}
placeholder="ν μΌμ λ§ν΄λ³΄μΈμ"
/>
<Button title="보λ΄κΈ°" onPress={sendMessage} />
</View>
</KeyboardAvoidingView>
);
}
π² 4. App.jsμ μ μ©
import ChatScreen from './src/screens/ChatScreen';
export default function App() {
return <ChatScreen />;
}
β μ΄λ² κΈμμ λ§λ κΈ°λ₯ μμ½
κΈ°λ₯ μλ£ μ¬λΆ
μ¬μ©μ λ©μμ§ μ λ ₯ | β |
GPTλ‘ λ©μμ§ μ μ‘ | β |
μλ΅ λ°μμ νλ©΄μ μΆλ ₯ | β |
μ±ν 리μ€νΈ UI ꡬν | β |
π λ€μ κΈ μκ³
λ€μ νΈμμλ GPTμ μλ΅μ λ¨μν λ§νμ ν
μ€νΈκ° μλλΌ
"ν μΌ λ±λ‘"μΌλ‘ λ³ννλ ꡬ쑰λ₯Ό λ§λλλ€.
- μ: “λ΄μΌ μ€ν 3μμ νμ μ‘μμ€” → λ μ§ + λ΄μ© μΆμΆ → Firestoreμ λ±λ‘
π GPT μλ΅μ “ꡬ쑰νλ JSON”μΌλ‘ λ°μμ TODOλ‘ μ μ₯νλ λ°©λ²μ λ°°μλ³Ό μ°¨λ‘μ λλ€!
React Native μ±λ΄ UI,React Native OpenAI μ°κ²°,React Native GPT μ±ν μμ ,React Native μ±ν μ± λ§λ€κΈ°,React Native GPT μ±λ΄ νλ©΄,chatgpt react native μμ ,OpenAI μ±ν μ± react native,μ±λ΄ μΈν°νμ΄μ€ ꡬν,react native todo μ±λ΄,React
'framework > ReactNative' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
- Total
- Today
- Yesterday
- seo μ΅μ ν 10κ°
- rag
- νλ‘ νΈμλλ©΄μ
- Webpack
- Next.js
- νλ‘ νΈμλ
- REACT
- κ°λ°λΈλ‘κ·Έ
- JAX
- Ktor
- νμ΄μ¬ μκ³ λ¦¬μ¦
- nodejs
- λ₯λ¬λ
- SEOμ΅μ ν
- CI/CD
- App Router
- λ°±μλκ°λ°
- AIμ±λ΄
- fastapi
- Docker
- llm
- μΉκ°λ°
- Prisma
- gatsbyjs
- SEO μ΅μ ν
- kotlin
- Python
- NestJS
- PostgreSQL
- nextJS
μΌ | μ | ν | μ | λͺ© | κΈ | ν |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |