-
Notifications
You must be signed in to change notification settings - Fork 16
/
srhfl.js
26 lines (22 loc) · 1.01 KB
/
srhfl.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { useCallback } from "react";
const getCurrentTimeFormatted = () => {
const currentTime = new Date();
const hours = currentTime.getHours();
const minutes = currentTime.getMinutes();
const seconds = currentTime.getSeconds();
const milliseconds = currentTime.getMilliseconds();
return `${hours}:${minutes}:${seconds}.${milliseconds}`;
}
const logger = (reducer) => {
const reducerWithLogger = useCallback((state, action) => {
const next = reducer(state, action);
console.group(`%cAction: %c${action.type} %cat ${getCurrentTimeFormatted()}`, "color: lightgreen; font-weight: bold;", "color: white; font-weight: bold;", "color: lightblue; font-weight: lighter;");
console.log("%cPrevious State:", "color: #9E9E9E; font-weight: 700;", state);
console.log("%cAction:", "color: #00A7F7; font-weight: 700;", action);
console.log("%cNext State:", "color: #47B04B; font-weight: 700;", next);
console.groupEnd();
return next;
}, [reducer]);
return reducerWithLogger;
}
export default logger;