<TextInput
style={styles.input}
placeholder='할 일을 입력하세요.'
value={text}
onChangeText={setText}
onSubmitEditing={() => addTodo()}
/>
// React
<input onChange((e) => setText(e.target.value)) />
// React Native
<TextInput onChangeText={setText} />
const deleteTodo = () => {
Alert.alert('Todo 삭제', '정말 삭제하시겠습니까?', [
{
text: '취소',
onPress: () => {
console.log('취소');
},
style: 'cancel',
},
{
text: '삭제',
onPress: () => {
console.log(`${text} 삭제`);
setTodos((prev) => prev.filter((todo) => todo.id !== id));
},
style: 'default',
},
]);
};
button 태그에 커스텀 스타일을 적용하기 위해서는 Pressable 또는 TouchableOpacity 컴포넌트를 사용한다.
export default function Button(props) {
const { onPress, title = 'Save' } = props;
return (
<Pressable style={styles.button} onPress={onPress}>
<Text style={styles.text}>{title}</Text>
</Pressable>
);
}
const styles = StyleSheet.create({
button: {
alignItems: 'center',
justifyContent: 'center',
paddingVertical: 12,
paddingHorizontal: 32,
borderRadius: 4,
elevation: 3,
backgroundColor: 'black',
},
text: {
fontSize: 16,
lineHeight: 21,
fontWeight: 'bold',
letterSpacing: 0.25,
color: 'white',
},
});
import { StyleSheet } from 'react-native';
export default function App() {
return (
<>
<Text style={styles.text}>title</Text>
</>
);
}
const styles = StyleSheet.create({
text: {
fontSize: 16,
lineHeight: 21,
fontWeight: 'bold',
letterSpacing: 0.25,
color: 'white',
},
});
References