refactor: add a unified warning function

This commit is contained in:
unix
2020-03-25 02:03:17 +08:00
parent 03578c2b68
commit 269a2bfae5
10 changed files with 46 additions and 17 deletions

View File

@@ -0,0 +1,18 @@
const warningStack: { [key: string]: boolean } = {}
const useWarning = (message: string, component?: string) => {
const tag = component ? ` [${component}]` : ' '
const log = `[Zeit UI]${tag}: ${message}`
if (typeof console === 'undefined') return
if (warningStack[log]) return
warningStack[log] = true
if (process.env.NODE_ENV !== 'production') {
return console.error(log)
}
console.warn(log)
}
export default useWarning