简体   繁体   English

Redux-Form的字段未编辑

[英]Field of Redux-Form not editing

I have this Field from Redux-Form: 我有来自Redux-Form的以下Field

          <Field
            name="hours"
            type="number"
            initialValue="100"
            placeholder="Ingrese las horas para esta categoría"
            component={RenderInput}
            onChange={(event) => {
              handleSubmit(currentValues => this.debounceSubmitProduction({
                ...currentValues,
                hours: event.target.value,
              }))();
            }}
          />

And I wanted to pass an initial value to an Input component initialValue="100" but now, the value appears in the input but I'm not able to edit it. 我想将初始值传递给Input组件initialValue="100"但是现在,该值出现在输入中,但是我无法对其进行编辑。

This is my RenderInput component: 这是我的RenderInput组件:

const RenderInput = ({
  input,
  type,
  disabled,
  readOnly,
  placeholder,
  meta: { touched, error },
  onKeyDown,
  innerRef,
  initialValue,
}) => (
  <div>
    <input
      {...input}
      type={type}
      value={initialValue}
      disabled={disabled}
      readOnly={readOnly}
      placeholder={placeholder}
      className={`font-300 ${touched && error && 'has-error'}`}
      onKeyDown={onKeyDown}
      ref={innerRef}
    />
  </div>
);

How can I edit the initial value passed to the input? 如何编辑传递给输入的初始值?

The issue is that you're setting the value equal to initialValue which does not change when you type. 问题是您将值设置为等于initialValue ,键入时该值不会更改。 You'll want to set the initial value in the redux-store when you're component is initialized and then set the value prop equal to the value returned from the store. 初始化组件时,您需要在redux-store中设置初始值,然后将prop的value设置为等于从商店返回的value onUpdate will update the store, and should then update the UI to reflect the change. onUpdate将更新商店,然后应更新UI以反映更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM