diff options
author | MikunoNaka <bokuwakanojogahoshii@yahoo.com> | 2021-04-16 22:20:43 +0530 |
---|---|---|
committer | MikunoNaka <bokuwakanojogahoshii@yahoo.com> | 2021-04-16 22:20:43 +0530 |
commit | f227adee3cff445288bdba66d369a451aa31b58e (patch) | |
tree | efa10970f366b9aa8628b5da656f17ec75b0a901 /src/components/BillingPage.js | |
parent | 034a41ad44144e79c1c58a3b4f8741ddf8d56f8c (diff) |
using useState to update array of items to be added in the invoice now
Diffstat (limited to 'src/components/BillingPage.js')
-rw-r--r-- | src/components/BillingPage.js | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/src/components/BillingPage.js b/src/components/BillingPage.js index ca51651..b06e876 100644 --- a/src/components/BillingPage.js +++ b/src/components/BillingPage.js @@ -1,6 +1,6 @@ -import React from "react"; -import AddNewItemForm from "./Form/AddNewItemForm.js"; - +import React, { useState } from "react"; +import AddNewItemForm from "./Form/AddNewItemForm"; +import ItemsDisplay from "./Display/ItemsDisplay"; const sampleData = [ { @@ -21,19 +21,24 @@ const sampleData = [ } ]; -// called when AddNewItemForm is submitted -let addedItems = []; -const getAddedItems = (item) => { - addedItems.push(item); -} - -const defGSTValue = 18; const BillingPage = () => { + const [items, setItems] = useState([]); + const defGSTValue = 18; + + const getItems = (item) => { + setItems( + [...items, item] + ); + } + + console.log(items) return ( - <> - <AddNewItemForm savedItems={sampleData} addItem={getAddedItems} defGSTValue={defGSTValue}/> - </> + <div> + <AddNewItemForm savedItems={sampleData} addItem={getItems} defGSTValue={defGSTValue}/> + + <ItemsDisplay/> + </div> ); } |