簡體   English   中英

Redux-Form的字段未編輯

[英]Field of Redux-Form not editing

我有來自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,
              }))();
            }}
          />

我想將初始值傳遞給Input組件initialValue="100"但是現在,該值出現在輸入中,但是我無法對其進行編輯。

這是我的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>
);

如何編輯傳遞給輸入的初始值?

問題是您將值設置為等於initialValue ,鍵入時該值不會更改。 初始化組件時,您需要在redux-store中設置初始值,然后將prop的value設置為等於從商店返回的value onUpdate將更新商店,然后應更新UI以反映更改。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM