0

I have just started learnig react i am stuck on this problem i have created an array expenses. There is no problem with declaration but it is throwing error while using it.

import ExpenseItem from "./components/ExpenseItem";
function App() {
const expenses = [
{
  id: "e1",
  title: "Toilet Paper",
  amount: 94.12,
  date: new Date(2020, 7, 14),
},
{ 
  id: "e2", 
  title: "New TV", 
  amount: 799.49,
  date: new Date(2021, 2, 12) 
 },

]; return (
<div>
  <h2>Let's get started!</h2>
  <ExpenseItem
    title={expenses[0].title}
    amount={expense[0].amount}
    date={expense[0].date}
  ></ExpenseItem>
  <ExpenseItem
    title={expenses[1].title}
    amount={expense[1].amount}
    date={expense[1].date}
  ></ExpenseItem>
</div>
    );
     }
   export default App;

And the error log is :

 src\App.js
 Line 23:17:  'expense' is not defined  no-undef
 Line 24:15:  'expense' is not defined  no-undef
 Line 28:17:  'expense' is not defined  no-undef
 Line 29:15:  'expense' is not defined  no-undef
3
  • you have 4 typos Commented Jan 22, 2022 at 7:25
  • Typos, expense isn't the same as expenses. Commented Jan 22, 2022 at 7:30
  • yeah my bad thanks for your time guys. Commented Jan 22, 2022 at 7:47

2 Answers 2

1

Looks like you misspelled expenses and instead wrote expense in your ExpenseItem element. Fixing the typo should fix your code.

Sign up to request clarification or add additional context in comments.

1 Comment

yeah its fixed.
0

function app should have returned:

return (
<div>
  <h2>Let's get started!</h2>
  <ExpenseItem
    title={expenses[0].title}
    amount={expenses[0].amount}
    date={expenses[0].date}
  ></ExpenseItem>
  <ExpenseItem
    title={expenses[1].title}
    amount={expenses[1].amount}sa
    date={expenses[1].date}
  ></ExpenseItem>
</div>
);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.