更新时间:2023-12-02 18:37:52
@Undefined I'll be using the same code from my answer here and will add the feature you're trying to implement on this post.
The reason why the changes of your MonthPicker
component's value is not reflecting to the formValue
is because you are passing the setMonth
as onChange
instead of handleInputChange
— basically the changes are stored only on the month
state.
Ideally we should be able to use the MonthPicker
like below, where we accept an event
from the onChange
prop that we can use to extract the target.name
and target.value
properties.
<MonthPicker
label="Start Date"
name="startDate"
onChange={(event) => handleInputChange(index, event)}
/>
I fixed and refactored your MonthPicker
component, so that everytime its value
change like incrementing/decrementing the year and selecting a month we'll call the onChange
prop passing its new value
.
Please check the demo below and if you have questions just let me know.