0

每当我@material-ui/pickers尝试从选择器更改日期和时间时,我都会遇到Formik错误React Class Component

TypeError : Cannot read property 'type' of undefined

下面是我的代码

// Handle fields change
handleChange = input => e => { 
 this.props.formikHandleChange(e);
 this.setState({ [input]: e.target.value });
};

<MuiPickersUtilsProvider utils={MomentUtils}>
   <DateTimePicker 
        label="Creation Date"
        name={creationDate}
        onChange={handleChange('creationDate')}
        value={values.creationDate} 
        onBlur={formikHandleBlur}
   />
</MuiPickersUtilsProvider>
4

2 回答 2

1

你可以使用 formik setFieldValue

  onChange={(date) =>
           setFieldValue(
             'creationDate',
                date
              )}
于 2021-02-24T08:01:19.880 回答
0
 // Handle fields change
handleChange = (e, input) => { 
 this.props.formikHandleChange(e);
 this.setState({ [input]: e.target.value });
};

<MuiPickersUtilsProvider utils={MomentUtils}>
   <DateTimePicker 
        label="Creation Date"
        name={creationDate}
        onChange={(e) => handleChange(e,input)}
        value={values.creationDate} 
        onBlur={formikHandleBlur}
   />
</MuiPickersUtilsProvider>

您可以设置属性[e.target.name]: e.target.value

于 2020-04-23T00:16:22.497 回答