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:
@@ -3,6 +3,7 @@ import useTheme from '../styles/use-theme'
|
||||
import withDefaults from '../utils/with-defaults'
|
||||
import useCurrentState from '../utils/use-current-state'
|
||||
import { FieldsetContext, FieldItem } from './fieldset-context'
|
||||
import useWarning from '../utils/use-warning'
|
||||
|
||||
interface Props {
|
||||
value: string
|
||||
@@ -26,7 +27,7 @@ const FieldsetGroup: React.FC<React.PropsWithChildren<FieldsetGroupProps>> = Rea
|
||||
const register = useCallback((newItem: FieldItem) => {
|
||||
const hasItem = ref.current.find(item => item.value === newItem.value)
|
||||
if (hasItem) {
|
||||
console.error('[Fieldset Group]: The "value" of each "Fieldset" must be unique.')
|
||||
useWarning('The "value" of each "Fieldset" must be unique.', 'Fieldset')
|
||||
}
|
||||
setItems([...ref.current, newItem])
|
||||
}, [])
|
||||
|
||||
@@ -6,6 +6,7 @@ import FieldsetFooter from './fieldset-footer'
|
||||
import FieldsetGroup from './fieldset-group'
|
||||
import { hasChild, pickChild } from '../utils/collections'
|
||||
import { useFieldset } from './fieldset-context'
|
||||
import useWarning from '../utils/use-warning'
|
||||
|
||||
interface Props {
|
||||
value?: string
|
||||
@@ -38,7 +39,7 @@ const Fieldset: React.FC<React.PropsWithChildren<FieldsetProps>> = React.memo(({
|
||||
|
||||
if (inGroup) {
|
||||
if (!label) {
|
||||
console.error('[Fieldset Group]: Props "label" is required when in a group.')
|
||||
useWarning('Props "label" is required when in a group.', 'Fieldset Group')
|
||||
}
|
||||
if (!value || value === '') {
|
||||
value = label
|
||||
|
||||
Reference in New Issue
Block a user