反应日期时间选择器
React DateTimePicker
使用 React DateTimePicker 我正在尝试更新更改的新日期,但它没有更新为新日期。谁能告诉我这里出了什么问题?
import DateTimePicker from 'react-datetime-picker';
const [values, setValues] = useState(new Date());
const onDateTimeChangeHandler = (newDate) => {
setValues(newDate);
};
<DateTimePicker
onChange={onDateTimeChangeHandler}
value={values}
/>
您错过了 return 声明。所以渲染中没有 returned。渲染 React 页面时需要添加 return 语句。
const App = () => {
const [values, setValues] = useState(new Date());
const onDateTimeChangeHandler = (newDate) => {
setValues(newDate);
};
return (
<DateTimePicker
onChange={onDateTimeChangeHandler}
value={values}
/>
)
}
这对你有用!
import React, { useState } from 'react';
import DateTimePicker from 'react-datetime-picker';
export default function App() {
const [values, setValues] = useState(new Date());
return (
<div>
<DateTimePicker
onChange={setValues}
value={values}
/>
</div>
);
}
使用 React DateTimePicker 我正在尝试更新更改的新日期,但它没有更新为新日期。谁能告诉我这里出了什么问题?
import DateTimePicker from 'react-datetime-picker';
const [values, setValues] = useState(new Date());
const onDateTimeChangeHandler = (newDate) => {
setValues(newDate);
};
<DateTimePicker
onChange={onDateTimeChangeHandler}
value={values}
/>
您错过了 return 声明。所以渲染中没有 returned。渲染 React 页面时需要添加 return 语句。
const App = () => {
const [values, setValues] = useState(new Date());
const onDateTimeChangeHandler = (newDate) => {
setValues(newDate);
};
return (
<DateTimePicker
onChange={onDateTimeChangeHandler}
value={values}
/>
)
}
这对你有用!
import React, { useState } from 'react';
import DateTimePicker from 'react-datetime-picker';
export default function App() {
const [values, setValues] = useState(new Date());
return (
<div>
<DateTimePicker
onChange={setValues}
value={values}
/>
</div>
);
}