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

@@ -4,6 +4,7 @@ import { useRadioContext } from './radio-context'
import RadioGroup from './radio-group'
import RadioDescription from './radio-description'
import { pickChild } from '../utils/collections'
import useWarning from '../utils/use-warning'
interface RadioEventTarget {
checked: boolean
@@ -43,10 +44,10 @@ const Radio: React.FC<React.PropsWithChildren<RadioProps>> = React.memo(({
if (inGroup) {
if (checked !== undefined) {
console.error('[Radio]: remove props "checked" if in the Radio.Group.')
useWarning('Remove props "checked" if in the Radio.Group.', 'Radio')
}
if (radioValue === undefined) {
console.error('[Radio]: props "value" must be deinfed if in the Radio.Group.')
useWarning('Props "value" must be deinfed if in the Radio.Group.', 'Radio')
}
useEffect(() => setSelfChecked(groupValue === radioValue), [groupValue, radioValue])
}