Skip to content

Commit d0d5945

Browse files
authored
Merge pull request #9 from tthordarson/console-log-grouped
Console log grouped per action
2 parents 4a3c271 + 272100f commit d0d5945

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

srhfl.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
import { useCallback } from "react";
22

3+
const getCurrentTimeFormatted = () => {
4+
const currentTime = new Date();
5+
const hours = currentTime.getHours();
6+
const minutes = currentTime.getMinutes();
7+
const seconds = currentTime.getSeconds();
8+
const milliseconds = currentTime.getMilliseconds();
9+
return `${hours}:${minutes}:${seconds}.${milliseconds}`;
10+
}
11+
312
const logger = (reducer) => {
413
const reducerWithLogger = useCallback((state, action) => {
514
const next = reducer(state, action);
15+
console.group(`%cAction: %c${action.type} %cat ${getCurrentTimeFormatted()}`, "color: lightgreen; font-weight: bold;", "color: white; font-weight: bold;", "color: lightblue; font-weight: lighter;");
616
console.log("%cPrevious State:", "color: #9E9E9E; font-weight: 700;", state);
717
console.log("%cAction:", "color: #00A7F7; font-weight: 700;", action);
818
console.log("%cNext State:", "color: #47B04B; font-weight: 700;", next);
19+
console.groupEnd();
920
return next;
1021
}, [reducer]);
1122

0 commit comments

Comments
 (0)