8000 refactor: improve 'unregistered icon' error message · coreui/coreui-icons-react@48bed04 · GitHub
[go: up one dir, main page]

Skip to content

Commit 48bed04

Browse files
committed
refactor: improve 'unregistered icon' error message
1 parent 7bcf299 commit 48bed04

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/CIcon.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import PropTypes from 'prop-types'
33
import classNames from 'classnames'
44
import './CIcon.css'
55

6-
const colog = (...args) => {
7-
if (process && process.env && process.env.NODE_ENV === 'development') {
8-
console.warn(...args)
6+
let warned = {}
7+
const colog = (msg, icon) => {
8+
if (!warned[icon] && process && process.env && process.env.NODE_ENV === 'development') {
9+
warned[icon] = true
10+
console.error(msg)
911
}
1012
}
1113

@@ -46,7 +48,11 @@ const CIcon = props => {
4648
return content
4749
} else if (name && React.icons) {
4850
return React.icons[iconName] ? React.icons[iconName] :
49-
colog('Not existing icon: '+ iconName + ' in React.icons object')
51+
colog(`CIcon component: icon name '${iconName}' does not exist in React.icons object. ` +
52+
`To use icons by 'name' prop you need to make them available globally ` +
53+
`by adding them to React.icons object. CIcon component docs: https://coreui.io/react/docs/components/CIcon \n`,
54+
iconName
55+
)
5056
}
5157
}, [change])
5258

0 commit comments

Comments
 (0)
0