-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcities.js
More file actions
45 lines (38 loc) · 939 Bytes
/
cities.js
File metadata and controls
45 lines (38 loc) · 939 Bytes
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
import React, {Component} from 'react';
import { Text, TextInput, View, StyleSheet } from 'react-native';
class App extends Component {
constructor(props){
super(props);
this.state = {
value: "",
cities:[]
}
}
handleChange = (newText) => {
this.setState({value: newText});
let url = "https://csonline.fhtl.org?q=" + newText;
fetch(url)
.then((data) => {
return (data.json());
})
.then((citylist) => {
console.log(citylist)
this.setState({cities:citylist})
});
}
render() {
return (
<>
<Text>Cities API</Text>
<TextInput
style={{height:40}}
placeholder="Enter a city"
onChangeText={newText => this.handleChange(newText)}
defaultValue={this.state.value}
/>
{this.state.cities.map((cityName) => <Text>{cityName.city}</Text>)}
</>
);
}
}
export default App;