so I have a function that sorts an array of activities based on their date. However, after sorting, it seems that I can't access an activity's property even though the activity is not null or undefined. Since English is not my native language, if there's anything unclear please tell me so that I can update the question. Thanks in advance guys.
The interface:
export interface IActivity {
id: string;
title: string;
description: string;
category: string;
date: Date | null;
city: string;
venue: string;
}
The function:
sortActivitiesByDate(activities: IActivity[]) {
const sortedActivities = activities.sort(
(a, b) => new Date(a.date).getTime() - new Date(b.date).getTime()
);
sortedActivities.forEach((activity) => {
const test = toJS(activity);
console.log(test); //has props in it
console.log(test.description); //undefined
});
}
The console result: Result
Please replcae console.log(test.description);
with console.log(test.activity.description);
and you will get your value in console.