Skip to content

Commit

Permalink
💫 Update: Ex - LogListDisplay
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicstop committed Oct 2, 2024
1 parent 39af079 commit e8e9913
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions example/src/components/LogListDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ export const LogListDisplay = React.forwardRef<

const hasEvents = (events.length > 0);
const maxItemsToShow = props.maxItemsToShow ?? 15;
const recentEvents = events.reverse().slice(-maxItemsToShow);

const recentEventsSorted = events.sort((a, b) => a.index - b.index);
const recentEvents = recentEventsSorted.reverse().slice(-maxItemsToShow);

React.useImperativeHandle(ref, () => ({
addItem: (itemTitle) => {
Expand All @@ -42,11 +44,14 @@ export const LogListDisplay = React.forwardRef<

const ms = Helpers.pad(date.getMilliseconds(), 3);

setEvents((prevValue) => ([ ...prevValue, {
timestamp: `${h}:${m}:${s}.${ms}`,
itemTitle: itemTitle,
index: prevValue.length
}]));
setEvents((prevValue) => ([
...prevValue,
{
timestamp: `${h}:${m}:${s}.${ms}`,
itemTitle: itemTitle,
index: prevValue.length
}
]));
},
}));

Expand Down

0 comments on commit e8e9913

Please sign in to comment.