From 3417e06b00c014546c805b5a642ad6fea9afcce6 Mon Sep 17 00:00:00 2001 From: Dabit Date: Sat, 6 Apr 2019 12:58:39 -0700 Subject: [PATCH] updated hooks --- AppWithHooks.js | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/AppWithHooks.js b/AppWithHooks.js index 78f79e7..6144014 100644 --- a/AppWithHooks.js +++ b/AppWithHooks.js @@ -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 = { @@ -103,31 +111,19 @@ function App() { return ( dispatch({ - type: 'updateInput', - inputValue: 'name', - value: v - })} + onChangeText={v => updater(v, 'name', dispatch)} value={state.name} style={{ height: 50, margin: 5, backgroundColor: "#ddd" }} /> dispatch({ - type: 'updateInput', - inputValue: 'description', - value: v - })} + onChangeText={v => updater(v, 'description', dispatch)} value={state.description} /> dispatch({ - type: 'updateInput', - inputValue: 'city', - value: v - })} + onChangeText={v => updater(v, 'city', dispatch)} value={state.city} />