Skip to content

Instantly share code, notes, and snippets.

@DavidWells
Created December 2, 2021 05:06
Show Gist options
  • Select an option

  • Save DavidWells/8facb75081291203839df7e5ca858fe9 to your computer and use it in GitHub Desktop.

Select an option

Save DavidWells/8facb75081291203839df7e5ca858fe9 to your computer and use it in GitHub Desktop.
Show warning just once via new Set()
// 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