Advertisement
Guest User

Untitled

a guest
May 9th, 2017
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from 'react';
  2. import {
  3.   AppRegistry,
  4.   StyleSheet,
  5.   Text,
  6.   View,
  7.   TextInput,
  8.   AsyncStorage
  9. } from 'react-native';
  10.  
  11. export default class DemoAsyncStorage extends Component {
  12.   constructor(props){
  13.     super(props)
  14.  
  15.     this.state = {
  16.       username:'',
  17.       password:''
  18.     }
  19.   }
  20.  
  21.   _saveData(){
  22.     AsyncStorage.setItem('username', this.state.username)
  23.   }
  24.  
  25.   render() {
  26.     return (
  27.       <View style={styles.container}>
  28.         <View style={{flexDirection:'row'}}>
  29.           <TextInput onChangeText={(value)=>this.setState({username:value})} placeholder={'username'} style={{flex:1}}/>
  30.         </View>
  31.  
  32.         <View style={{flexDirection:'row'}}>
  33.           <TextInput onChangeText={(value)=>this.setState({password:value})} placeholder={'password'} style={{flex:1}}/>
  34.         </View>
  35.  
  36.         <View style={{flexDirection:'row', marginTop:20}}>
  37.           <Text onPress={this._saveData.bind(this)}>Save</Text>
  38.         </View>
  39.  
  40.         <View style={{flexDirection:'row', marginTop:20}}>
  41.           <Text>Load</Text>
  42.         </View>
  43.       </View>
  44.     );
  45.   }
  46. }
  47.  
  48. const styles = StyleSheet.create({
  49.   container: {
  50.     flex: 1
  51.   }
  52. });
  53.  
  54. AppRegistry.registerComponent('AsyncStorage', () => DemoAsyncStorage);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement