Advertisement
zidniryi

Searching.js

Dec 2nd, 2020
470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from 'react';
  2. import axios from 'axios';
  3. import { View, Text, TextInput } from 'react-native';
  4. import EventEmitter from 'event-emitter';
  5.  
  6. const api =
  7.   'https://api.github.com/repos/yilung7817/react-native-test/issues?access_token=b754068dd7931c3fa2855763fa0e620359ef32a5';
  8.  
  9. import { Dispatcher } from 'flux';
  10.  
  11. class AppDispatcher extends Dispatcher {
  12.   handleViewAction(action) {
  13.     this.dispatch({
  14.       action: action,
  15.     });
  16.   }
  17. }
  18.  
  19. export var dispatcher = new AppDispatcher();
  20.  
  21. export default class App extends React.Component {
  22.   constructor(props, context) {
  23.     super(props, context);
  24.     this.state = {
  25.       issues: [],
  26.       search: '',
  27.     };
  28.   }
  29.  
  30.   componentDidMount() {
  31.     // this.getApi();
  32.   }
  33.  
  34.   getApi(api) {
  35.     this.setState({search:api})
  36.     setTimeout(() => {
  37.       axios
  38.         .get(`https://api.github.com/users/${this.state.search}`)
  39.         .then((response) => {
  40.           var issues = response.data;
  41.           this.setState({
  42.             issues: issues,
  43.           });
  44.         });
  45.     }, 2000);
  46.   }
  47.  
  48.   render() {
  49.     return (
  50.       <View>
  51.         <TextInput
  52.           value={this.state.search}
  53.           onChangeText={(text) => this.getApi(text)}
  54.           style={{ width: 200, height: 200, borderWidth: 1 }}
  55.         />
  56.         <Text>{JSON.stringify(this.state.issues)}</Text>
  57.       </View>
  58.     );
  59.   }
  60. }
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement