AuthContext.js
1.23 KB
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
41
42
43
44
45
46
47
48
import React, {createContext, useEffect} from 'react';
import {Text} from "react-native";
import {useDispatch, useSelector} from "react-redux";
import {loadMeReducer} from "./reducers/user";
import styled from "styled-components";
export const AuthContext = createContext({});
export const AuthProvider = (props) => {
const {children, user} = props;
const {info} = useSelector(state => state.info);
const dispatch = useDispatch();
useEffect(() => {
if (user) {
dispatch({
type: loadMeReducer,
data: {user}
});
}
}, [user]);
return (
<AuthContext.Provider>
{children}
{info
? <Info><Text
style={{
textAlign: 'center',
fontSize: 14,
color: '#bc324a'
}}>{info}</Text></Info>
: <></>
}
</AuthContext.Provider>
)
};
const Info = styled.TouchableOpacity`
position: absolute;
right: 10px;
bottom: 10px;
width: 300px;
height: 50px;
border-radius: 5px;
border: 1px solid #17174B;
backgroundColor: #ffffff;
justifyContent: center;
`;