-
Notifications
You must be signed in to change notification settings - Fork 0
/
HeaderComponent.jsx
40 lines (35 loc) · 1.03 KB
/
HeaderComponent.jsx
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
31
32
33
34
35
36
37
38
39
40
import React from "react";
import { View, Text, Button, StyleSheet } from "react-native";
import { useDispatch, useSelector } from "react-redux";
import { logout } from "../ReduxComonents/features/userSlice";
import { useNavigation } from "@react-navigation/native";
const Header = (handleLogout) => {
const dispatch = useDispatch();
const isLogedIn = useSelector((state) => state.user.isLogedIn);
const navigation = useNavigation();
const user = useSelector((state) => state.user.userData);
if (!isLogedIn) {
navigation.navigate("Login");
return;
}
return (
<View style={styles.header}>
<Text style={styles.headerText}>Welcome, {user.name}!</Text>
<Button title="Logout" onPress={handleLogout} color="#FF6347" />
</View>
);
};
const styles = StyleSheet.create({
header: {
flexDirection: "row",
justifyContent: "space-between",
alignItems: "center",
padding: 20,
backgroundColor: "#007BFF",
},
headerText: {
color: "white",
fontSize: 20,
},
});
export default Header;