1 回答

TA貢獻(xiàn)1744條經(jīng)驗(yàn) 獲得超4個贊
React 在單向流中工作。因此,您需要調(diào)用回調(diào)處理程序作為道具來實(shí)現(xiàn)這一點(diǎn)。
您應(yīng)該對此稍微修改一下代碼:
export default function BasicDateTimePicker({
selectedDate,
handleDateChange
}) {
return (
<MuiPickersUtilsProvider utils={DateFnsUtils}>
<DateTimePicker
allowKeyboardControl
ampm
animateYearScrolling
initialFocusedDate
value={selectedDate}
disablePast
onChange={handleDateChange}
format=" dd/MM/yyyy hh:mm:ss a "
showTodayButton
/>
</MuiPickersUtilsProvider>
);
}
import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import * as serviceWorker from "./serviceWorker";
import BasicDateTimePicker from "./components/BasicDateTimePicker";
const DateTime = () => {
var date = new Date();
const [selectedDate, handleDateChange] = useState(
new Date(date.setMonth(date.getMonth() + 6))
);
return (
<>
<BasicDateTimePicker selectedDate={selectedDate} handleDateChange={handleDateChange} />
<h1>{selectedDate}</h1>
</>
);
};
ReactDOM.render(
<React.StrictMode>
<DateTime />
</React.StrictMode>,
document.getElementById("root")
);
serviceWorker.unregister();
添加回答
舉報(bào)