Javascript 单击按钮时添加“反应选择”下拉列表组件

Javascript 单击按钮时添加“反应选择”下拉列表组件,javascript,reactjs,Javascript,Reactjs,我试图在点击按钮时添加一个组件。我正在使用react select下拉包。 我尝试使用concat,但它给出了一个错误,并且没有添加到DOM中。 这是我的jsx文件 const LanguageSelect = (props) => { const {options, name, isLanguage} = props; const [language, setLanguage] = useState([{ value: '', label: '' }]); // Inp

我试图在点击按钮时添加一个组件。我正在使用react select下拉包。 我尝试使用concat,但它给出了一个错误,并且没有添加到DOM中。 这是我的jsx文件

const LanguageSelect = (props) => {
    const {options, name, isLanguage} = props;
    const [language, setLanguage] = useState([{ value: '', label: '' }]);
 // Input Change 
    const handleSelectDropdownChange = (selected, index) => {
        const {value, label} = selected;
        const list = [...inputList];
        list[value, label] = language;
        setLanguage(list);
        console.log(list);
    }

    // handle to add language dropdown
    const handleAddClick = () => {
        setInputList([...inputList, {value: "", label: ""}]);
        <LanguageSelect options={options} placeholder={placeholder} name={name} isLanguageBlock={isLanguageBlock} title={title} />
    }
return (
<div className="form-group">
            <label htmlFor={name} className="control-label">{title}</label>
                <div className="form-input-container">
                    <Select 
                        className="profile-module-select-container"
                        classNamePrefix="profile-module-select"
                        options={options}
                        onChange={selected => {
                            setDropdown({
                                optionSelect: selected.value
                            });
                            handleSelectDropdownChange(selected, i);
                        }}
                    />{isLanguage && (<div className="add-language-selection">
                    <a className="addLanguage" id="addLanguage" role="link" onClick={handleAddClick} tabIndex={0}>+Add Language</a> 
                    </div>)}
                </div>
            </div>
    )
}
const language选择=(道具)=>{
const{options,name,isLanguage}=props;
const[language,setLanguage]=useState([{value:'',label:''}]);
//输入变化
常量handleSelectDropdownChange=(选定,索引)=>{
常量{值,标签}=选中;
常量列表=[…输入列表];
列表[值,标签]=语言;
设置语言(列表);
控制台日志(列表);
}
//添加语言下拉列表的句柄
const handleAddClick=()=>{
setInputList([…inputList,{value:,label:}]);
}
返回(
{title}
{
设置下拉列表({
选项选择:已选择。值
});
handleSelectDropdownChange(已选,i);
}}
/>{岛屿语言&&(
+添加语言
)}
)
}

如果要基于单击添加新组件,可以在列表循环中渲染该组件,例如:

languageList.map((item, index) => return (
<LanguageSelect key={index} name={item.name} otherFields={item.otherFields} /> 
))

顺便问一下,你使用什么css框架?没有框架,所有css都是用scss编写的。我使用的命名约定与BootstrapThis类似。这也给出了一个错误。错误是什么?没有错误,但在DOM中没有添加下拉列表。我使用的数据源与我传递的数据源相同,用于呈现原始下拉列表。谢谢!我没有用正确的方法,但这种方法起了作用。将其标记为正确答案。
setLanguageList([...languageList, {name: '', otherFields:''}])