Created
February 16, 2020 21:46
-
-
Save AllGistsEqual/54db325dc352d597a72288cc4f85dac5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState } from 'react' | |
import { Text, TextInput, Button } from 'react-native' | |
import { connect } from 'react-redux' | |
import PropTypes from 'prop-types' | |
import DefaultPage from '../../components/DefaultPage' | |
import { userLogin } from '../../redux/actions/user.actions' | |
const SceneLogin = ({ loginUser, isUserLoggedIn, storedUserName }) => { | |
const [name, setName] = useState('') | |
return ( | |
<DefaultPage> | |
<Text> | |
Login | |
</Text> | |
<TextInput | |
style={{ | |
height: 50, width: 200, borderColor: 'gray', borderWidth: 3, padding: 10, margin: 10, | |
}} | |
onChangeText={(text) => setName(text)} | |
value={name} | |
/> | |
<Button | |
title="Press me" | |
onPress={() => loginUser(name || 'Anon')} | |
/> | |
{ isUserLoggedIn ? (<Text>{`Welcome, ${storedUserName}!`}</Text>) : undefined} | |
</DefaultPage> | |
) | |
} | |
SceneLogin.defaultProps = { | |
storedUserName: '', | |
} | |
SceneLogin.propTypes = { | |
loginUser: PropTypes.func.isRequired, | |
isUserLoggedIn: PropTypes.bool.isRequired, | |
storedUserName: PropTypes.string, | |
} | |
const mapStateToProps = (state) => ({ | |
storedUserName: state.user.name, | |
isUserLoggedIn: state.user.isLoggedIn, | |
}) | |
const mapDispatchToProps = (dispatch) => ({ | |
loginUser: (name) => dispatch(userLogin({ name })), | |
}) | |
export default connect(mapStateToProps, mapDispatchToProps)(SceneLogin) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment