我正在尝试编写事件处理程序以更新组件中某个字段的字段。我的组件具有以下属性...
deliveryConfirmationImage: null
deliveryLocation: {address: "639 N Westmoreland Ave, Los Angeles, CA 90004,
pickUpWindow: {startTime: "2020-05-17T18:58:28.829545", timeWindowType: "whenever possible"}
请注意,pickUpWindow本身就是一个具有自己属性的对象。我的伴侣中有这个...
const { handleChange, values } = useForm(mission);
...
function handleChangePickupWindow(data) {
const { time } = data;
const name = "pickUpWindow";
const value = {startTime: time};
handleChange({ target: { name, value } });
}
...
<DateTimeInput
dateInputProps={{
id: "date-pickup",
label: "Pickup Date",
}}
onChange={handleChangePickupWindow}
required
timeInputProps={{
id: "time-pickup",
label: "Pickup Time",
}}
value={values.pickUpWindow.startTime}
/>
我在其中定义“ handleChange”钩子,就像这样...
const handleChange = ({ target }) => {
setValues((values) => ({
...values,
[target.name]: target.value,
}));
};
但是可悲的是,尽管我看到传递给句柄更改事件处理程序的时间的正确值,但我不知道如何更新“值”对象中的相应项以正确地更新组件-即“ values.pickUpWindow”。即使我尝试对其进行更改,“ startTime”也始终保持相同的值。我还需要做些什么来更新我的基础字段?