我需要創建一個const組件來呈現選項及其選項,但是由於代碼返回的選項沒有任何選項,因此無法呈現選項字段。問題在哪裏?無法從const數組映射中渲染
謝謝你的建議。
import React from "react";
const FilterSelect = (props) => {
const {title, name, selectedValue, optionsValue, onChange} = {...props};
const renderOptions = (optionsValue) => {
optionsValue.map((optionValue, i) =>
<option value={optionValue.value} key={i}>{optionValue.name}</option>
);
};
return (
<div className="filters-content-block">
<h3 className="filters-subtitle">{title}</h3>
<select className="sl sl-fullwidth" onChange={onChange} required>
{renderOptions}
</select>
</div>
);
};
export default FilterSelect;
在我看來,這是最好的解決辦法,所以我用它更改我的代碼。謝謝! – Aitor