Sir, please help me to get rid out of this typeError
My order index.js code
import React, { useState } from "react";import { useDispatch, useSelector } from "react-redux"; import { updateOrder } from "../../actions"; import Layout from "../Layout"; import Card from "../UI/Card"; import "./style.css"; /** * @author * @function Orders **/ const Orders = (props) => { const order = useSelector((state) => state.order); const [type, setType] = useState(""); const dispatch = useDispatch(); const onOrderUpdate = (orderId) => { const payload = { orderId, type, }; dispatch(updateOrder(payload)); }; const formatDate = (date) => { if (date) { const d = new Date(date); return `${d.getFullYear()}-${d.getMonth() + 1}-${d.getDate()}`; } return ""; }; return ( {order.orders.map((orderItem, index) => (
order.action.js
import axios from "../helpers/axios";import { orderConstants } from "./constants"; export const getCustomerOrders = () => { return async (dispatch) => { dispatch({ type: orderConstants.GET_CUSTOMER_ORDER_REQUEST }); try { const res = await axios.post("/order/getCustomerOrders"); if (res.status === 200) { const { orders } = res.data; dispatch({ type: orderConstants.GET_CUSTOMER_ORDER_SUCCESS, payload: { orders }, }); } else { const { error } = res.data; dispatch({ type: orderConstants.GET_CUSTOMER_ORDER_FAILURE, payload: { error }, }); } } catch (error) { console.log(error); } }; }; export const updateOrder = (payload) => { return async (dispatch) => { dispatch({ type: orderConstants.UPDATE_CUSTOMER_ORDER_REQUEST }); try { const res = await axios.post("/order/update", payload); if (res.status === 201) { dispatch({ type: orderConstants.UPDATE_CUSTOMER_ORDER_SUCCESS }); dispatch(getCustomerOrders()); } else { const { error } = res.data; dispatch({ type: orderConstants.UPDATE_CUSTOMER_ORDER_FAILURE, payload: { error }, }); } } catch (error) { console.log(error); } }; };
order.reducer.js
import { orderConstants } from "../actions/constants"; const initState = { orders: [1], }; export default (state = initState, action) => { switch (action.type) { case orderConstants.GET_CUSTOMER_ORDER_SUCCESS: console.log("FAIL") state = { ...state, orders: action.payload.orders, }; break; } return state; };
Loading..!