mirror of
https://github.com/zhigang1992/react.git
synced 2026-04-26 23:04:55 +08:00
refactor: add a unified warning function
This commit is contained in:
18
components/utils/use-warning.ts
Normal file
18
components/utils/use-warning.ts
Normal 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
|
||||
Reference in New Issue
Block a user