当我在渲染或更改某些依赖项时获取数据时,它会正确地更新Redux存储中的数据,但在Console.Log时,它会给出‘Undefined’.
我正在开发预订系统,想在指定的日期取回已经预订的时间
/// Fetch data on render the component and try to console.log
useEffect(() => {
axios
.get(
`http://localhost/healthboyz/index.php/booked/${
formData.doctor_id
}/${moment(formData.date).format('YYYY-MM-DD')}`
)
.then((res) => setBookedHrs(res.data))
.then(() => console.log(bookedHrs))
.catch((e) => console.log(e));},
[formData.doctor_id, formData.date]);
/// Hours reducer
const hoursReducerDefaultState: {
bookedHrs: string[];
} = {
bookedHrs: [],
};
export const hoursReducer = (
state = hoursReducerDefaultState,
action: {
type: string;
data: string[];
}
) => {
switch (action.type) {
case 'SET_BOOKED_HRS':
return [...action.data];
default:
return state;
}
};