Unexpected Application Error, in using redux and react ,array

So here i want to show the data of customers from redux and the data is successfulls stored in redux I checked it with ReactDevTools the error is when i use useSelect to retrive the data from the redux toom
error:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>TypeError: entries.map is not a function
at Entries (http://localhost:5173/src/pages/Entries.jsx?t=1718705214409:80:59)
at renderWithHooks (http://localhost:5173/node_modules/.vite/deps/chunk-QO4NA2F3.js?v=1f9f66b9:11568:26)
at mountIndeterminateComponent (http://localhost:5173/node_modules/.vite/deps/chunk-QO4NA2F3.js?v=1f9f66b9:14946:21)
at beginWork (http://localhost:5173/node_modules/.vite/deps/chunk-QO4NA2F3.js?v=1f9f66b9:15934:22)
at beginWork$1 (http://localhost:5173/node_modules/.vite/deps/chunk-QO4NA2F3.js?v=1f9f66b9:19781:22)
at performUnitOfWork (http://localhost:5173/node_modules/.vite/deps/chunk-QO4NA2F3.js?v=1f9f66b9:19226:20)
at workLoopSync (http://localhost:5173/node_modules/.vite/deps/chunk-QO4NA2F3.js?v=1f9f66b9:19165:13)
at renderRootSync (http://localhost:5173/node_modules/.vite/deps/chunk-QO4NA2F3.js?v=1f9f66b9:19144:15)
at recoverFromConcurrentError (http://localhost:5173/node_modules/.vite/deps/chunk-QO4NA2F3.js?v=1f9f66b9:18764:28)
at performConcurrentWorkOnRoot (http://localhost:5173/node_modules/.vite/deps/chunk-QO4NA2F3.js?v=1f9f66b9:18712:30)
</code>
<code>TypeError: entries.map is not a function at Entries (http://localhost:5173/src/pages/Entries.jsx?t=1718705214409:80:59) at renderWithHooks (http://localhost:5173/node_modules/.vite/deps/chunk-QO4NA2F3.js?v=1f9f66b9:11568:26) at mountIndeterminateComponent (http://localhost:5173/node_modules/.vite/deps/chunk-QO4NA2F3.js?v=1f9f66b9:14946:21) at beginWork (http://localhost:5173/node_modules/.vite/deps/chunk-QO4NA2F3.js?v=1f9f66b9:15934:22) at beginWork$1 (http://localhost:5173/node_modules/.vite/deps/chunk-QO4NA2F3.js?v=1f9f66b9:19781:22) at performUnitOfWork (http://localhost:5173/node_modules/.vite/deps/chunk-QO4NA2F3.js?v=1f9f66b9:19226:20) at workLoopSync (http://localhost:5173/node_modules/.vite/deps/chunk-QO4NA2F3.js?v=1f9f66b9:19165:13) at renderRootSync (http://localhost:5173/node_modules/.vite/deps/chunk-QO4NA2F3.js?v=1f9f66b9:19144:15) at recoverFromConcurrentError (http://localhost:5173/node_modules/.vite/deps/chunk-QO4NA2F3.js?v=1f9f66b9:18764:28) at performConcurrentWorkOnRoot (http://localhost:5173/node_modules/.vite/deps/chunk-QO4NA2F3.js?v=1f9f66b9:18712:30) </code>
TypeError: entries.map is not a function
    at Entries (http://localhost:5173/src/pages/Entries.jsx?t=1718705214409:80:59)
    at renderWithHooks (http://localhost:5173/node_modules/.vite/deps/chunk-QO4NA2F3.js?v=1f9f66b9:11568:26)
    at mountIndeterminateComponent (http://localhost:5173/node_modules/.vite/deps/chunk-QO4NA2F3.js?v=1f9f66b9:14946:21)
    at beginWork (http://localhost:5173/node_modules/.vite/deps/chunk-QO4NA2F3.js?v=1f9f66b9:15934:22)
    at beginWork$1 (http://localhost:5173/node_modules/.vite/deps/chunk-QO4NA2F3.js?v=1f9f66b9:19781:22)
    at performUnitOfWork (http://localhost:5173/node_modules/.vite/deps/chunk-QO4NA2F3.js?v=1f9f66b9:19226:20)
    at workLoopSync (http://localhost:5173/node_modules/.vite/deps/chunk-QO4NA2F3.js?v=1f9f66b9:19165:13)
    at renderRootSync (http://localhost:5173/node_modules/.vite/deps/chunk-QO4NA2F3.js?v=1f9f66b9:19144:15)
    at recoverFromConcurrentError (http://localhost:5173/node_modules/.vite/deps/chunk-QO4NA2F3.js?v=1f9f66b9:18764:28)
    at performConcurrentWorkOnRoot (http://localhost:5173/node_modules/.vite/deps/chunk-QO4NA2F3.js?v=1f9f66b9:18712:30)

App.jsx where all the data is dispactched in store

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>useEffect(() => {
const initializeApp = async () => {
try {
const userData = await authService.getCurrentUser();
if (userData) {
dispatch(login({ userData }));
} else {
dispatch(logout());
}
const entries = await service.getEntries();
if (entries ) {
dispatch(setEntries(entries));
}
} catch (error) {
console.error('Initialization error:', error);
} finally {
setLoading(false);
}
};
initializeApp();
}, [dispatch]);
</code>
<code>useEffect(() => { const initializeApp = async () => { try { const userData = await authService.getCurrentUser(); if (userData) { dispatch(login({ userData })); } else { dispatch(logout()); } const entries = await service.getEntries(); if (entries ) { dispatch(setEntries(entries)); } } catch (error) { console.error('Initialization error:', error); } finally { setLoading(false); } }; initializeApp(); }, [dispatch]); </code>
useEffect(() => {
    const initializeApp = async () => {
      try {
        const userData = await authService.getCurrentUser();
        if (userData) {
          dispatch(login({ userData }));
        } else {
          dispatch(logout());
        }

        const entries = await service.getEntries();
        if (entries ) {
          dispatch(setEntries(entries));
      }
      } catch (error) {
        console.error('Initialization error:', error);
      } finally {
        setLoading(false);
      }
    };

    initializeApp();
  }, [dispatch]);


Entries.jsx Where I am trying to show the data

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>
import React from 'react';
import { useSelector } from 'react-redux';
import { Link } from 'react-router-dom';
function Entries() {
const entries = useSelector(state => state.entry.entries)
console.log(entries);
return (
<div className='flex flex-col'>
<div className='mb-4'>
<Link className='bg-slate-600 text-white p-2 rounded' to='/addentry'>Add Entry</Link>
</div>
<div className="w-full">
{entries.length === 0 ? (
<div>No entries available</div>
) : (
<table className="min-w-full bg-white">
<thead>
<tr>
<th className="py-2">Customer Name</th>
<th className="py-2">Document Name</th>
<th className="py-2">Reception Date</th>
<th className="py-2">Submitter's Name</th>
<th className="py-2">Restitution Date</th>
<th className="py-2">Collector's Name</th>
</tr>
</thead>
<tbody>
{entries.map((entry) => (
<tr key={entry.id} className="text-center border-b">
<td className="py-2">{entry.customer_name}</td>
<td className="py-2">{entry.document_name}</td>
<td className="py-2">{entry.date}</td>
<td className="py-2">{entry.submitors_name}</td>
<td className="py-2">{entry.restitution_date }</td>
<td className="py-2">{entry.collectors_name}</td>
</tr>
))}
</tbody>
</table>
)}
</div>
</div>
);
}
export default Entries;
</code>
<code> import React from 'react'; import { useSelector } from 'react-redux'; import { Link } from 'react-router-dom'; function Entries() { const entries = useSelector(state => state.entry.entries) console.log(entries); return ( <div className='flex flex-col'> <div className='mb-4'> <Link className='bg-slate-600 text-white p-2 rounded' to='/addentry'>Add Entry</Link> </div> <div className="w-full"> {entries.length === 0 ? ( <div>No entries available</div> ) : ( <table className="min-w-full bg-white"> <thead> <tr> <th className="py-2">Customer Name</th> <th className="py-2">Document Name</th> <th className="py-2">Reception Date</th> <th className="py-2">Submitter's Name</th> <th className="py-2">Restitution Date</th> <th className="py-2">Collector's Name</th> </tr> </thead> <tbody> {entries.map((entry) => ( <tr key={entry.id} className="text-center border-b"> <td className="py-2">{entry.customer_name}</td> <td className="py-2">{entry.document_name}</td> <td className="py-2">{entry.date}</td> <td className="py-2">{entry.submitors_name}</td> <td className="py-2">{entry.restitution_date }</td> <td className="py-2">{entry.collectors_name}</td> </tr> ))} </tbody> </table> )} </div> </div> ); } export default Entries; </code>

import React from 'react';
import { useSelector } from 'react-redux';
import { Link } from 'react-router-dom';

function Entries() {
    const entries = useSelector(state => state.entry.entries)
    
    console.log(entries);

    return (
        <div className='flex flex-col'>
            <div className='mb-4'>
                <Link className='bg-slate-600 text-white p-2 rounded' to='/addentry'>Add Entry</Link>
            </div>

            <div className="w-full">
                {entries.length === 0 ? (
                    <div>No entries available</div>
                ) : (
                    <table className="min-w-full bg-white">
                        <thead>
                            <tr>
                                
                                
                                <th className="py-2">Customer Name</th>
                                <th className="py-2">Document Name</th>
                                <th className="py-2">Reception Date</th>
                                <th className="py-2">Submitter's Name</th>
                                <th className="py-2">Restitution Date</th>
                                <th className="py-2">Collector's Name</th>
                            </tr>
                        </thead>
                        <tbody>
                            {entries.map((entry) => (
                                <tr key={entry.id} className="text-center border-b">
                                    
                                   
                                    <td className="py-2">{entry.customer_name}</td>
                                    <td className="py-2">{entry.document_name}</td>
                                    <td className="py-2">{entry.date}</td>
                                    <td className="py-2">{entry.submitors_name}</td>
                                    <td className="py-2">{entry.restitution_date }</td>
                                    <td className="py-2">{entry.collectors_name}</td>
                                </tr>
                            ))}
                        </tbody>
                    </table>
                )}
            </div>
        </div>
    );
}

export default Entries;

service class:
(I have used proxy here therefor half url and its working correctly)

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import axios from 'axios';
export class Service {
async createEntry({ docName, subName }) {
try {
const response = await axios.post('/api/v1/e', {
docName,
subName
});
return response.data;
} catch (error) {
console.log("Custom backend service :: createEntry :: error", error);
}
}
async updateEntry({ docName, subName, entryid }) {
try {
const url = `/api/v1/e/${entryid}`;
const response = await axios.put(url, {
docName, subName
});
return response.data;
} catch (error) {
console.log("Custom backend service :: updateEntry :: error", error);
}
}
async deleteEntry(entryid) {
try {
const url = `/api/v1/e/${entryid}`;
await axios.delete(url);
return true;
} catch (error) {
console.log("Custom backend service :: deleteEntry :: error", error);
return false;
}
}
async getEntries() {
try {
const response = await axios.get('api/v1/e');
return response.data;
} catch (error) {
console.log("Custom backend service :: getEntries :: error", error);
return false;
}
}
async getEntry(entryid) {
try {
const response = await axios.get('/api/v1/e');
return response.data.data;
} catch (error) {
console.log("Custom backend service :: getPost :: error", error);
return false;
}
}
}
const service = new Service();
export default service;
</code>
<code>import axios from 'axios'; export class Service { async createEntry({ docName, subName }) { try { const response = await axios.post('/api/v1/e', { docName, subName }); return response.data; } catch (error) { console.log("Custom backend service :: createEntry :: error", error); } } async updateEntry({ docName, subName, entryid }) { try { const url = `/api/v1/e/${entryid}`; const response = await axios.put(url, { docName, subName }); return response.data; } catch (error) { console.log("Custom backend service :: updateEntry :: error", error); } } async deleteEntry(entryid) { try { const url = `/api/v1/e/${entryid}`; await axios.delete(url); return true; } catch (error) { console.log("Custom backend service :: deleteEntry :: error", error); return false; } } async getEntries() { try { const response = await axios.get('api/v1/e'); return response.data; } catch (error) { console.log("Custom backend service :: getEntries :: error", error); return false; } } async getEntry(entryid) { try { const response = await axios.get('/api/v1/e'); return response.data.data; } catch (error) { console.log("Custom backend service :: getPost :: error", error); return false; } } } const service = new Service(); export default service; </code>
import axios from 'axios';

export class Service {
    
    async createEntry({ docName, subName }) {
        try {
            const response = await axios.post('/api/v1/e', {
                docName,
                subName
            });
            return response.data;
        } catch (error) {
            console.log("Custom backend service :: createEntry :: error", error);
        }
    }

    async updateEntry({ docName, subName, entryid }) {
        try {
            const url = `/api/v1/e/${entryid}`;
            const response = await axios.put(url, {
                docName, subName
            });
            return response.data;
        } catch (error) {
            console.log("Custom backend service :: updateEntry :: error", error);
        }
    }
    
    async deleteEntry(entryid) {
        try {
            const url = `/api/v1/e/${entryid}`;
            await axios.delete(url);
            return true;
        } catch (error) {
            console.log("Custom backend service :: deleteEntry :: error", error);
            return false;
        }
    }
    
    async getEntries() {
        try {
            const response = await axios.get('api/v1/e');
            return response.data;
        } catch (error) {
            console.log("Custom backend service :: getEntries :: error", error);
            return false;
        }
    }
    async getEntry(entryid) {
        try {
            const response = await axios.get('/api/v1/e');
            return response.data.data;
        } catch (error) {
            console.log("Custom backend service :: getPost :: error", error);
            return false;
        }
    }
}

const service = new Service();
export default service;

entrySlice.js:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>
import { createSlice } from "@reduxjs/toolkit";
const initialState = {
entries: [],
};
const entrySlice = createSlice({
name: "entry",
initialState,
reducers: {
setEntries: (state, action) => {
state.entries = action.payload;
},
addEntry: (state, action) => {
state.entries.push(action.payload);
},
},
});
export const { setEntries, addEntry } = entrySlice.actions;
export default entrySlice.reducer;
</code>
<code> import { createSlice } from "@reduxjs/toolkit"; const initialState = { entries: [], }; const entrySlice = createSlice({ name: "entry", initialState, reducers: { setEntries: (state, action) => { state.entries = action.payload; }, addEntry: (state, action) => { state.entries.push(action.payload); }, }, }); export const { setEntries, addEntry } = entrySlice.actions; export default entrySlice.reducer; </code>

import { createSlice } from "@reduxjs/toolkit";

const initialState = {
    entries: [],
};

const entrySlice = createSlice({
    name: "entry",
    initialState,
    reducers: {
        setEntries: (state, action) => {
            state.entries = action.payload; 
        },
        addEntry: (state, action) => {
            state.entries.push(action.payload);
        },
    },
});

export const { setEntries, addEntry } = entrySlice.actions;

export default entrySlice.reducer;

Store.js:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>
import {configureStore} from '@reduxjs/toolkit';
import authSlice from './slice/authSlice';
import custSlice from './slice/custSlice';
import entrySlice from './slice/entrySlice';
const store = configureStore({
reducer: {
auth : authSlice,
entry: entrySlice,
customer: custSlice,
}
});
export default store;
</code>
<code> import {configureStore} from '@reduxjs/toolkit'; import authSlice from './slice/authSlice'; import custSlice from './slice/custSlice'; import entrySlice from './slice/entrySlice'; const store = configureStore({ reducer: { auth : authSlice, entry: entrySlice, customer: custSlice, } }); export default store; </code>

import {configureStore} from '@reduxjs/toolkit';
import authSlice from './slice/authSlice';
import custSlice from './slice/custSlice';
import entrySlice from './slice/entrySlice';

const store = configureStore({
    reducer: {
        auth : authSlice,
        entry: entrySlice,
        customer: custSlice,
        
    }
});


export default store;

data example from Post man

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>
{
"statusCode": 200,
"data": [
{
"id": 1,
"customer_id": null,
"employe_id": null,
"document_name": "Pan",
"reception_date": "2024-03-04T18:30:00.000Z",
"submitors_name": "ved bhoskar",
"restitution_date": null,
"collectors_name": null
},
{
"id": 2,
"customer_id": null,
"employe_id": null,
"document_name": "Pan",
"reception_date": "2024-03-04T18:30:00.000Z",
"submitors_name": "ved bhoskar",
"restitution_date": null,
"collectors_name": null
},
],
"message": "Entries retrieved successfully",
"success": true
}
</code>
<code> { "statusCode": 200, "data": [ { "id": 1, "customer_id": null, "employe_id": null, "document_name": "Pan", "reception_date": "2024-03-04T18:30:00.000Z", "submitors_name": "ved bhoskar", "restitution_date": null, "collectors_name": null }, { "id": 2, "customer_id": null, "employe_id": null, "document_name": "Pan", "reception_date": "2024-03-04T18:30:00.000Z", "submitors_name": "ved bhoskar", "restitution_date": null, "collectors_name": null }, ], "message": "Entries retrieved successfully", "success": true } </code>

{
    "statusCode": 200,
    "data": [
        {
            "id": 1,
            "customer_id": null,
            "employe_id": null,
            "document_name": "Pan",
            "reception_date": "2024-03-04T18:30:00.000Z",
            "submitors_name": "ved bhoskar",
            "restitution_date": null,
            "collectors_name": null
        },
        {
            "id": 2,
            "customer_id": null,
            "employe_id": null,
            "document_name": "Pan",
            "reception_date": "2024-03-04T18:30:00.000Z",
            "submitors_name": "ved bhoskar",
            "restitution_date": null,
            "collectors_name": null
        },
],
    "message": "Entries retrieved successfully",
    "success": true
}

and any changes I should make?
Suggestions are welcomed

console logging entries

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật