Почему эта ошибка будет выброшена для моего сборщика дат? - PullRequest
0 голосов
/ 22 сентября 2019

Я не знаю, почему, но когда я работал над некоторыми, казалось бы, не связанными вещами в том же файле, эта ошибка начала появляться, и я понятия не имею, с чего это началось.до этого все работало нормально, я даже не касался областей, выделяющих ошибки:

index.js:1375 Warning: Failed prop type: Invalid prop `value` of type `string` supplied to `DatePicker`, expected `object`.
    in DatePicker (created by ReduxFormMaterialUIDatePicker)
    in ReduxFormMaterialUIDatePicker (created by ConnectedField)
    in ConnectedField (created by ConnectFunction)
    in ConnectFunction (created by Connect(ConnectedField))
    in Connect(ConnectedField) (created by Field)
    in Field (created by Context.Consumer)
    in Hoc (created by Field)
    in Field (at AddWorkout.jsx:47)
    in form (at AddWorkout.jsx:46)
    in div (at AddWorkout.jsx:44)
    in AddWorkout (created by Form(AddWorkout))
    in Form(AddWorkout) (created by ConnectFunction)
    in ConnectFunction (created by Connect(Form(AddWorkout)))
    in Connect(Form(AddWorkout)) (created by ReduxForm)
    in ReduxForm (created by Context.Consumer)
    in Hoc (created by ReduxForm)
    in ReduxForm (at AddWorkoutForm.jsx:33)
...

Я в замешательстве.Я попытался вернуться, прежде чем что-то коснуться, и ошибка осталась ... Моя цель - создать значение по умолчанию в качестве текущей даты для поля DatePicker.

const AddWorkout = ({ handleSubmit, submitting }) => (
  <div style={{ textAlign: "center" }}>
    <h2>Enter Your Workout Details</h2>
    <form onSubmit={handleSubmit} style={styles.form}>
      <Field
        name="date"
        component={DatePicker}
        format={null}
        hintText="Date Of Workout"
        fullWidth={true}
        locale="en-US"
      />
      <Field
        name="name"
        component={TextField}
        floatingLabelText="Workout Name"
        style={styles.textfield}
      />
      <Field
        name="duration"
        type="number"
        component={TextField}
        floatingLabelText="Estimated Duration"
        style={styles.textfield}
      />
      <FieldArray name="exercises" component={renderExercises} />
      <div style={styles.buttonWrapper}>
        <Button
          type="submit"
          color="primary"
          variant="contained"
          size="large"
          disabled={submitting}
          style={styles.button}
        >
          Submit
        </Button>
      </div>
    </form>
  </div>
);

const renderExercises = ({ fields, meta: { error, submitFailed } }) => (
  <>
    {/* {console.log(numberOfSets)} */}
    {fields.map((exercise, idx) => {
      return (
        <div key={idx}>
          <Field
            floatingLabelText="Exercise Name"
            name={`${exercise}.exerciseName`}
            component={TextField}
          />
          <FieldArray name={`${exercise}.sets`} component={renderSets} />
          <Button
            onClick={() => fields.remove(idx)}
            size="small"
            disableRipple
            fullWidth
          >
            REMOVE EXERCISE
          </Button>
        </div>
      );
    })}
    <Button
      type="button"
      size="small"
      disableRipple
      fullWidth
      onClick={() => fields.push({})}
    >
      Add Exercise
    </Button>
    {submitFailed && error && <span style={{ color: "red" }}>{error}</span>}
  </>
);

const renderSets = ({ fields }) => (
  <>
    <IconButton onClick={() => fields.push({})} size="small">
      <AddBoxIcon color="primary" />
    </IconButton>
    {fields.map((sets, idx) => (
      <div style={{ height: "80px" }} key={idx}>
        <Field
          floatingLabelText="Weight"
          type="number"
          name={`${sets}.weight`}
          component={TextField}
          style={styles.textfieldSet}
        />
        <Field
          floatingLabelText="Reps"
          type="number"
          name={`${sets}.reps`}
          component={TextField}
          style={styles.textfieldSet}
        />
        <IconButton
          onClick={() => fields.remove(idx)}
          style={styles.buttonSet}
          size="small"
        >
          <DeleteIcon color="secondary" />
        </IconButton>
      </div>
    ))}
  </>
);


export default reduxForm({
  form: "addworkout", // a unique identifier for this form
  initialValues: {
    date: new Date()
  },
  destroyOnUnmount: false,
  validate
})(AddWorkout);

Любая помощь приветствуется!

...