Hard
In a React application, you need to create a tag input component where users can add and remove tags. The component should prevent duplicates and validate input. What's wrong with this implementation?
1function TagInput({ value = [], onChange, maxTags = 5 }) {2 const [inputValue, setInputValue] = useState('');34 const handleKeyDown = (e) => {5 if (e.key === 'Enter') {6 e.preventDefault();7 const tag = inputValue.trim().toLowerCase();89 if (tag && value.length < maxTags) {10 onChange([...value, tag]);11 setInputValue('');12 }13 } else if (e.key === 'Backspace' && !inputValue) {14 onChange(value.slice(0, -1));15 }16 };1718 return (19 <div className="tag-input">20 {value.map((tag, index) => (21 <span key={index} className="tag">22 {tag}23 <button24 onClick={() => onChange(value.filter((_, i) => i !== index))}25 className="remove"26 >27 ×28 </button>29 </span>30 ))}31 <input32 type="text"33 value={inputValue}34 onChange={(e) => setInputValue(e.target.value)}35 onKeyDown={handleKeyDown}36 placeholder={value.length < maxTags ? "Add tag..." : ""}37 disabled={value.length >= maxTags}38 />39 </div>40 );41}