Created
December 2, 2021 05:06
-
-
Save DavidWells/8facb75081291203839df7e5ca858fe9 to your computer and use it in GitHub Desktop.
Show warning just once via new Set()
This file contains hidden or 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
| // https://github.com/satya164/warn-once/blob/main/index.js | |
| const DEV = process.env.NODE_ENV !== "production"; | |
| const warnings = new Set(); | |
| function warnOnce(condition, ...rest) { | |
| if (DEV && condition) { | |
| const key = rest.join(" "); | |
| if (warnings.has(key)) { | |
| return; | |
| } | |
| warnings.add(key); | |
| console.warn(...rest); | |
| } | |
| } | |
| module.exports = warnOnce; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment