mirror of
https://github.com/zhigang1992/react.git
synced 2026-04-24 04:15:54 +08:00
refactor: add a unified warning function
This commit is contained in:
@@ -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) => {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user