/** @format */ import React, { useState, useEffect } from 'react'; import QueueAnim from 'rc-queue-anim'; import isEqual from 'lodash/isEqual'; import { Container } from './styled'; interface OnlineLessonListProps { data: Record[]; limit: number; size: { width: number; height: number; }; } const OnlineLessonList = (props: OnlineLessonListProps) => { const { data = [], limit = 4, size: { width, height } } = props; const [key, setKey] = useState('-1'); const [cachedData, setCachedData] = useState[]>([]); useEffect(() => { if (!isEqual(data, cachedData)) { setCachedData(data); } }, [data]); useEffect(() => { setKey(new Date().getTime().toString()); }, [cachedData, limit, height]); const formatData = data && data.length ? data.slice(0, limit) : []; return ( {data && data.length ? formatData.map((item: Record) => (
{item.name}
评分 {item.score}
{item.studyNum || 0}人已学习
)) : null}
); }; export default OnlineLessonList;