Created
October 9, 2022 17:42
-
-
Save dturton/de57ac157e410f69b343bdd095cfa21b to your computer and use it in GitHub Desktop.
JSON.stringify() -- Converting circular structure to JSON - workaround
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getCircularReplacer = () => { | |
const seen = new WeakSet(); | |
return (_key: any, value: object) => { | |
if (typeof value === "object" && value !== null) { | |
if (seen.has(value)) { | |
return; | |
} | |
seen.add(value); | |
} | |
return value; | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment