import React, { useState } from "react";
import { StyleSheet, SafeAreaView, Text, Button } from "react-native";
const App = () => {
const [user, setUser] = useState({ id: 1, name: "Mehmet" });
const handlePress = () => {
// setUser({ ...user, id: 2 }); //...user ın o anki halini alabiliriz ardından üzerindeki değişiklikleri yaptırabiliriz.
// setUser({ ...user, name: "Ahmet" });
setUser((prev) => ({ ...prev, name: "Ahmet" }));
};
return (
<SafeAreaView style={styles.container}>
<Text style={styles.text}>ID: {user.id}</Text>
<Text style={styles.text}>ID: {user.name}</Text>
<Button title="Click" onPress={handlePress} />
</SafeAreaView>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
},
text: {
fontSize: 20,
},
});
export default App;