Skip to content

Commit

Permalink
refactor: improve 'unregistered icon' error message
Browse files Browse the repository at this point in the history
  • Loading branch information
woothu committed Jul 23, 2020
1 parent 7bcf299 commit 48bed04
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/CIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import PropTypes from 'prop-types'
import classNames from 'classnames'
import './CIcon.css'

const colog = (...args) => {
if (process && process.env && process.env.NODE_ENV === 'development') {
console.warn(...args)
let warned = {}
const colog = (msg, icon) => {
if (!warned[icon] && process && process.env && process.env.NODE_ENV === 'development') {
warned[icon] = true
console.error(msg)
}
}

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

Expand Down

0 comments on commit 48bed04

Please sign in to comment.