Push is not a function in redux?

Answer

The main problem here is that you are setting the value of state.products to the value returned by push(). The push() method does not return an array. It mutates the array, which you should not do in Redux, and returns the new length. After you call this reducer you will have changed your state.products property from an array to a number.

You can use concat() instead. This method returns a new array with the item appended to it. It does not modify the original array so it's Redux-safe.

I'm not too familiar with redux-sauce, but it seems like you need to include state = INITIAL_STATE on every case reducer.

export const AddToCart = (state = INITIAL_STATE, { item }) => ({
...state,
products: state.products.concat(item),
});

 

 

All react js Questions

Ask your interview questions on react-js

Write Your comment or Questions if you want the answers on react-js from react-js Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---