【发布时间】:2020-01-27 05:02:30
【问题描述】:
你能告诉我为什么我的初始值没有在反应中设置吗?我正在使用react-final-form
这是我的代码
https://codesandbox.io/s/frosty-star-1qcw3
我的初始值打印在控制台中,但没有设置在下拉菜单中
react final 形式的API链接
https://final-form.org/docs/react-final-form/examples
const [options, setOptions] = useState([]);
useEffect(() => {
console.log("urllll");
// (async () => {
// setOptions(await getDropDowOptions(dataKey));
// })();
console.log(options);
console.log(value);
(() => {
setOptions(getDropDowOptions(dataKey));
})();
}, []);
const getDropDowOptions = dataKey => {
console.log(dataKey);
switch (dataKey) {
case "abc":
console.log("========");
const slots = [
{
key: "9-13",
label: "09:00-13:00",
value: "09:00-13:00"
},
{
key: "13:00-16:00",
label: "13:00-16:00",
value: "13:00-16:00"
},
{
key: "16:00-19:00",
label: "16:00-19:00",
value: "5000"
}
];
return slots;
}
};
【问题讨论】:
标签: javascript reactjs react-final-form final-form