Advertisement
Guest User

Untitled

a guest
Mar 6th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. import React from "react";
  2. import { View, Text, TextInput, Button } from "react-native";
  3. import { IRootState } from "../store";
  4. import { login } from "../auth/thunks";
  5. import { connect } from 'react-redux';
  6.  
  7. interface ILoginState{
  8. username:string,
  9. password:string
  10. }
  11.  
  12. interface ILoginProps{
  13. login: (username:string,password:string)=> any
  14. }
  15.  
  16. class LoginScreen extends React.Component<ILoginProps,ILoginState> {
  17. constructor(props:ILoginProps){
  18. super(props);
  19. this.state = {
  20. username:"",
  21. password:""
  22. }
  23. }
  24.  
  25. private onChangeUsername = ( text:string) => {
  26. this.setState({
  27. username:text
  28. });
  29. }
  30.  
  31. private onChangePassword = ( text:string) => {
  32. this.setState({
  33. password:text
  34. });
  35. }
  36.  
  37. private onLoginPressed = () => {
  38. this.props.login(this.state.username, this.state.password)
  39. }
  40.  
  41. public render() {
  42. return (
  43. <View style={{alignItems: 'center', justifyContent: 'center', flex: 1}}>
  44. <View>
  45. <Text>Username</Text>
  46. <TextInput
  47. value={this.state.username}
  48. onChangeText= {(text)=>this.onChangeUsername(text)}
  49. placeholder="Type in Username" />
  50. </View>
  51. <View>
  52. <Text>Password</Text>
  53. <TextInput
  54. value={this.state.password}
  55. secureTextEntry={true}
  56. onChangeText= {(text)=>this.onChangePassword(text)}
  57. placeholder="Type in Password" />
  58. </View>
  59. <Button title="Login" onPress={this.onLoginPressed} />
  60. </View>
  61. )
  62. }
  63. }
  64.  
  65.  
  66. const mapStateToProps = (state:IRootState)=>({});
  67.  
  68. const mapDispatchToProps = (dispatch:any)=>({
  69. login: (username:string,password:string)=>dispatch(login(username,password))
  70. })
  71.  
  72. export default connect(mapStateToProps,mapDispatchToProps)(LoginScreen)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement