IanKaneshiro / KaneKare

Designing a app to help families better manage caregivers for loved ones.
0 stars 0 forks source link

The User model needs to be iterable. Mongoose document is not translating well to JS/TSX #2

Open jhalton opened 3 months ago

jhalton commented 3 months ago

The issue I am having is that I haven't been able to get the User object to render. The issue seems to be that mongoose documents are different from plain JS objects. I need to be able to iterate over the User model in order to populate a chart. I have tried several methods to try to get it to transform: • .lean( ) • Object.entries( ) -- and other variations of this • Skipping the helper function portion of this and directly setting up the function in the admin-page file.

I'm not quite sure what the issue is yet, and I will have to do some more research to figure out how to get the data to behave in a way that makes it accessible in the tsx.

jhalton commented 3 months ago

Note: I am successfully able to get the User data and can console.log it. It will log all the information associated with the users as well as all users currently in the DB.

jhalton commented 3 months ago

The typeof for user data received is an array when I console.log. When I try to use that same returned data in tsx, it converts again to an object and won't become iterable. So, console.log data === array (checked via Array.isArray( )). Data when returned otherwise is an object of some kind. Very frustrating.