Skip to content

Commit 76272b2

Browse files
committed
Add search input
1 parent 0902e28 commit 76272b2

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/screens/home.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
import React, { Component } from 'react';
2-
import { ScrollView, Text, View } from 'react-native'
2+
import { ScrollView, Text, View, TextInput, Button, Alert } from 'react-native'
33
import { EXAMPLE } from '../graphql/queries';
44
import { Query } from "react-apollo";
55

66

77
export default class Home extends Component {
8-
getYelp({ term, location }) {
8+
constructor(props) {
9+
super(props);
10+
this.state = {
11+
term: "burrito",
12+
location: "san francis"
13+
}
14+
}
15+
16+
getYelp = () => {
17+
const { term, location } = this.state;
918
return (
1019
<Query query={EXAMPLE} variables={{ term, location }}>
1120
{({ loading, data: { search }, error }) => {
21+
1222
if (loading) {
1323
return <Text>Loading...</Text>
1424
}
@@ -33,11 +43,14 @@ export default class Home extends Component {
3343
</Query>
3444
)
3545
}
36-
render() {
3746

47+
render() {
48+
const { term } = this.state;
3849
return (
3950
<ScrollView>
40-
{this.getYelp({ term: "burrito", location: "san francis" })}
51+
<TextInput onChangeText={(term) => this.setState({ term })} value={term}></TextInput>
52+
<Text>Result for: {this.state.term}</Text>
53+
{this.getYelp("pizza", "new york")}
4154
</ScrollView>
4255
)
4356
}

0 commit comments

Comments
 (0)