diff --git a/packages/components/tag-input/useTagList.tsx b/packages/components/tag-input/useTagList.tsx index 7dbdc4826e..d29526bc6c 100644 --- a/packages/components/tag-input/useTagList.tsx +++ b/packages/components/tag-input/useTagList.tsx @@ -1,5 +1,6 @@ import React, { Fragment, useState } from 'react'; import { isFunction } from 'lodash-es'; +import log from '@tdesign/common-js/log/index'; import useConfig from '../hooks/useConfig'; import useControlled from '../hooks/useControlled'; @@ -23,7 +24,20 @@ export default function useTagList(props: TagInputProps) { const readOnly = props.readOnly || props.readonly; // handle controlled property and uncontrolled property - const [tagValue, setTagValue] = useControlled(props, 'value', props.onChange); + const [innerTagValue, setTagValue] = useControlled(props, 'value', props.onChange); + let tagValue: TagInputValue; + if (Array.isArray(innerTagValue)) { + tagValue = innerTagValue; + } else { + if (innerTagValue !== undefined && innerTagValue !== null) { + log.warnOnce( + 'TagInput', + `\`value\` is expected to be an array, but got ${typeof innerTagValue}. It will be treated as an empty array.`, + ); + } + tagValue = []; + } + // eslint-disable-next-line @typescript-eslint/no-unused-vars const [oldInputValue, setOldInputValue] = useState();