Skip to content

Commit 80d9539

Browse files
authored
Merge pull request #5 from victorporof/master
Don't execute reducer multiple times
2 parents 0590e92 + c91ba00 commit 80d9539

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,8 @@
2222
"url": "https://github.com/jefflombard/simple-react-hook-flux-logger/issues"
2323
},
2424
"homepage": "https://github.com/jefflombard/simple-react-hook-flux-logger#readme",
25-
"types": "./index.d.ts"
25+
"types": "./index.d.ts",
26+
"peerDependencies": {
27+
"react": "^16.8"
28+
}
2629
}

srhfl.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
import { useCallback } from "react";
2+
13
const logger = (reducer) => {
2-
const reducerWithLogger = (state, action) => {
4+
const reducerWithLogger = useCallback((state, action) => {
5+
const next = reducer(state, action);
36
console.log("%cPrevious State:", "color: #9E9E9E; font-weight: 700;", state);
47
console.log("%cAction:", "color: #00A7F7; font-weight: 700;", action);
5-
console.log("%cNext State:", "color: #47B04B; font-weight: 700;", reducer(state,action));
6-
return reducer(state,action);
7-
};
8+
console.log("%cNext State:", "color: #47B04B; font-weight: 700;", next);
9+
return next;
10+
}, [reducer]);
11+
812
return reducerWithLogger;
913
}
1014

0 commit comments

Comments
 (0)