javascript - Redux-Form 字段未编辑
问题描述
我Field
从 Redux-Form 得到这个:
<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 中设置初始值,然后将value
prop 设置为等于value
从商店返回的值。 onUpdate
将更新商店,然后应该更新 UI 以反映更改。
推荐阅读
- wordpress - SQL Query 用于获取具有某些元键的特定类型的所有帖子
- javascript - Javascript 按 X 值过滤
- netty - 使用 Bazel 安装带有动态链接的 netty-tcnative
- javascript - Photoshop,如何对动作调色板进行脚本更改
- kubernetes - 如果没有入口可用于其他服务,Nginx Ingress 将重定向到第一个服务
- python - 如果它们以相同的 int 开头,则合并 pandas df 行
- python - 比 Counter 对象上的两倍 for 循环快
- c++ - c++ 变量未在范围错误和不匹配类型警告中声明的问题
- r - 用两个步骤对 R 中的数据框进行子集化
- javascript - React JS styled-components 从公共文件夹导入图像