我用 redux 表单为 react-datepicker 输入代码,它可以工作,但是当我选择日期时,页面中的所有内容都会消失并得到控制台错误,时间值无效,请在此处输入代码
import React from "react";
import { Form, Label } from "semantic-ui-react";
import DatePicker from "react-datepicker";
import "react-datepicker/dist/react-datepicker.css";
import moment from "moment";
const DateInput = ({
input: { value, onChange, ...restInput },
width,
placeholder,
meta: { touched, error },
...rest
}) => {
return (
<Form.Field error={touched && !!error} width={width}>
<DatePicker
{...rest}
placeholderText={placeholder}
selected={value ? moment(value) : value}
onChange={onChange}
{...restInput}
/>
{touched && error && (
<Label basic color="red">
{error}
</Label>
)}
</Form.Field>
);
};
export default DateInput;
<Field
name="date"
type="text"
component={DateInput}
dateFormat="YYYY-MM-DD HH:mm"
timeFormat="HH:mm"
showTimeSelect
placeholder="Date and time of event"
/>