Skip to content

Commit

Permalink
article solutionExample.js 2
Browse files Browse the repository at this point in the history
  • Loading branch information
KnightSlayer committed Mar 2, 2023
1 parent 12c44b5 commit e6d6be5
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions article/solutionExample.js
@@ -1,11 +1,15 @@
export const withMemo = (originFn) => {
let cache;
const cache = {
value: undefined,
isCached: false,
};

return () => {
if (cache === undefined) {
cache = originFn();
if (!cache.isCached) {
cache.value = originFn();
cache.isCached = true;
}

return cache;
return cache.value;
};
};

0 comments on commit e6d6be5

Please sign in to comment.