Skip to content

Commit

Permalink
updated hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
Dabit committed Apr 6, 2019
1 parent df52e99 commit 3417e06
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions AppWithHooks.js
Expand Up @@ -58,6 +58,14 @@ async function getRestaurants(dispatch) {
}
}

const updater = (value, inputValue, dispatch) => {
dispatch({
type: 'updateInput',
value,
inputValue
})
}

async function CreateRestaurant(state, dispatch) {
const { name, description, city } = state
const restaurant = {
Expand Down Expand Up @@ -103,31 +111,19 @@ function App() {
return (
<View style={styles.container}>
<TextInput
onChangeText={v => dispatch({
type: 'updateInput',
inputValue: 'name',
value: v
})}
onChangeText={v => updater(v, 'name', dispatch)}
value={state.name}
style={{ height: 50, margin: 5, backgroundColor: "#ddd" }}
/>
<TextInput
placeholder="description"
style={{ height: 50, margin: 5, backgroundColor: "#ddd" }}
onChangeText={v => dispatch({
type: 'updateInput',
inputValue: 'description',
value: v
})}
onChangeText={v => updater(v, 'description', dispatch)}
value={state.description}
/>
<TextInput
style={{ height: 50, margin: 5, backgroundColor: "#ddd" }}
onChangeText={v => dispatch({
type: 'updateInput',
inputValue: 'city',
value: v
})}
onChangeText={v => updater(v, 'city', dispatch)}
value={state.city}
/>
<Button onPress={() => CreateRestaurant(state, dispatch)} title='Create Restaurant' />
Expand Down Expand Up @@ -167,3 +163,4 @@ const styles = StyleSheet.create({
});

export default App

0 comments on commit 3417e06

Please sign in to comment.