const monthGrop = useMemo = return = bookListredcesum item = const key = dateFormatitemdate return sumkey sumkeypushitem sumkey = item bookList错误了怎么改
错误的地方在于书写拼写错误,应该是reduce而不是redce。
正确的代码应该是:
const monthGroup = useMemo(() => {
return bookList.reduce((sum, item) => {
const key = dateFormat(item.date);
sum[key] ? sum[key].push(item) : (sum[key] = [item]);
return sum;
}, {});
}, [bookList]);
修正后的代码使用reduce函数对bookList进行遍历,并根据日期格式化后的结果作为键值,将相同日期的书籍放入同一个数组中。最终返回一个包含按月份分组的对象。
原文地址: https://www.cveoy.top/t/topic/izVK 著作权归作者所有。请勿转载和采集!