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

@@ -1,6 +1,7 @@
import React, { useEffect, useMemo, useState } from 'react'
import withDefaults from '../utils/with-defaults'
import { CheckboxContext } from './checkbox-context'
import useWarning from '../utils/use-warning'
interface Props {
value: string[]
@@ -22,7 +23,7 @@ const CheckboxGroup: React.FC<React.PropsWithChildren<CheckboxGroupProps>> = Rea
const [selfVal, setSelfVal] = useState<string[]>([])
if (!value) {
value = []
console.error('[Checkbox Group]: Props "value" is required.')
useWarning('Props "value" is required.', 'Checkbox Group')
}
const updateState = (val: string, checked: boolean) => {

View File

@@ -2,6 +2,7 @@ import React, { useCallback, useEffect, useState } from 'react'
import { useCheckbox } from './checkbox-context'
import CheckboxGroup from './checkbox-group'
import CheckboxIcon from './checkbox.icon'
import useWarning from '../utils/use-warning'
interface CheckboxEventTarget {
checked: boolean
@@ -41,11 +42,17 @@ const Checkbox: React.FC<CheckboxProps> = React.memo(({
const isDisabled = inGroup ? disabledAll || disabled : disabled
if (inGroup && !value) {
console.error('[Checkbox]: Props "value" must be set when [Checkbox] component is in the group.')
useWarning(
'Props "value" must be set when [Checkbox] component is in the group.',
'Checkbox',
)
}
if (inGroup && checked) {
console.error('[Checkbox]: Remove props "checked" when [Checkbox] component is in the group.')
useWarning(
'Remove props "checked" when [Checkbox] component is in the group.',
'Checkbox',
)
}
if (inGroup) {