Giter Club home page Giter Club logo

reducer.js:23 Uncaught TypeError: Cannot read properties of undefined (reading 'type') i'm calulating total price of basket but it shows this error in inspect>> console .shows error in reducer,js >>>> " switch (action.type)" about react-challenge-amazon-clone HOT 4 OPEN

cleverprogrammers avatar cleverprogrammers commented on August 26, 2024
reducer.js:23 Uncaught TypeError: Cannot read properties of undefined (reading 'type') i'm calulating total price of basket but it shows this error in inspect>> console .shows error in reducer,js >>>> " switch (action.type)"

from react-challenge-amazon-clone.

Comments (4)

ubongn avatar ubongn commented on August 26, 2024

can I see the code?

from react-challenge-amazon-clone.

minal322 avatar minal322 commented on August 26, 2024

this one is reducer.js file

export const initialState = {
basket: [],
user : null

};

export const getBasketTotal = (basket) =>
basket?.reduce((amount,item) => item.price+amount,0);

/export const getBasketTotal = (basket) => {
const total = basket
.map((item) => item.price)
.reduce((acc, value) => acc - value, 0);
return total;
};
/

const reducer = (state, action) => {

switch (action.type) {
case "ADD_TO_BASKET":
return {
...state,
basket : [...state.basket, action.item],
};

  default:
    return state;
}

};

export default reducer;

from react-challenge-amazon-clone.

minal322 avatar minal322 commented on August 26, 2024

checkout.js >>>> here suybtotall.js file is called.

function Checkout() {
const [{ basket, user }, dispatch] = useStateValue();

return (



    <div>
      <h3>Hello, { user?.email}</h3>
      <h2 className="checkout_title">Your shopping Basket</h2>

      {basket.map(item => (
        <CheckoutProduct
          id={item.id}
          title={item.title}
          image={item.image}
          price={item.price}
          rating={item.rating}
        />
      ))}

    </div>
  </div>

  <div className="checkout_right">
       <Subtotall />
  </div>
</div>

);
}

export default Checkout;

from react-challenge-amazon-clone.

minal322 avatar minal322 commented on August 26, 2024

subtotall.js file >>>>
unction Subtotall() {
const history = useNavigate();
const [{ basket}, dispatch] = useStateValue();

return (


<CurrencyFormat
renderText={(value) => (
<>


Subtotal ({basket.length} items) : value



This order contains a gift

</>

  )}
  decimalScale={2}
  value = {getBasketTotal(basket)}    //error exist here
  displayType={"text"}
  thousandSeparator={true}
  prefix={"₹"}
/>

<button  onClick={e => history('/payment')}>Proceed to Checkout and Check Total Price </button>
); }

export default Subtotall;

from react-challenge-amazon-clone.

Related Issues (20)

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.