Code Monkey home page Code Monkey logo

expense-tracker-react's Issues

App is blank after adding GlobalProvider to app.js.

import { Header } from './components/Header';
import { Balance } from './components/Balance';
import { IncomeExpenses } from './components/IncomeExpenses';
import { TransactionList } from './components/TransactionList';
import { AddTransaction } from './components/AddTransaction';

import { GlobalProvider } from './context/GlobalState';

// css imports
import './App.css';

function  App() {
  return (
    <GlobalProvider>
      <Header />
      <div className="container">
        <Balance />
        <IncomeExpenses />
        <TransactionList />
        <AddTransaction />
      </div>
    </GlobalProvider>
  );
}

export default App;

app is showing nothing in the browser after this addition. please help.

An error is thrown from Balance component when the Transactions length is 0

The following line in Balance component:
const balance = amounts.reduce((acc, amount) => acc + amount).toFixed(2);

throws this error if the transactions list is empty:

TypeError: Reduce of empty array with no initial value

I have updated the line with this:
const balance = amounts.length > 0 ? amounts.reduce((acc, amount) => acc + amount).toFixed(2) : 0;

Same error occurs for same reason for the following lines in IncomeExpenses component:

const income =  amounts.filter(amount => amount > 0).reduce((acc, amount) => acc + amount).toFixed(2);
const expense = (amounts.filter(amount => amount < 0).reduce((acc, amount) => acc + amount) * -1).toFixed(2);

I have updated those lines with these:

const income = amounts.length > 0 && amounts.filter(amount => amount > 0).length > 0 ? amounts.filter(amount => amount > 0).reduce((acc, amount) => acc + amount).toFixed(2) : 0.00;
const expense = amounts.length > 0 && amounts.filter(amount => amount < 0).length > 0 ? (amounts.filter(amount => amount < 0).reduce((acc, amount) => acc + amount) * -1).toFixed(2) : 0.00;

Missing pre-sign if balance is negative

I've played a bit around with your nice app.
Thanks for sharing it here.

I've found that in case of negative balance the - is missing in front of the value.
I've fixed this with my PR #24

BTW:
If you cherish this PR, please add a label to the aprove of the PR named : 'hacktoberfest-accepted'
Thanx.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.