【发布时间】:2018-07-10 07:55:20
【问题描述】:
我正在使用 redux-form 并将 material-ui 的 TextField 作为 prop 发送到 redux-form 的字段。但其他属性都按预期进行。
<Field
id="firstName"
name="firstName"
floatingLabelText="Username"
errorText={this.state.firstNameError}
component={TextInputField}
/>
下面是 TextInputField 组件的代码
import React from 'react';
import PropTypes from 'prop-types';
import TextField from 'material-ui/TextField';
import _noop from 'lodash/noop';
const TextInputField = ({
hintText,
id,
name,
className,
defaultValue,
floatingLabelText,
errorText,
onFocus,
onChange,
onBlur
}) => {
return (
<TextField
hintText={hintText}
id={id}
name={name}
className={className}
defaultValue={defaultValue}
floatingLabelText={floatingLabelText}
errorText={errorText}
onFocus={onFocus}
onChange={onChange}
onBlur={onBlur}
/>
);
};
export default TextInputField;
这里的问题是名称 prop 在我使用组件的地方未定义。我不知道这是在哪里发生的。当我安慰名称道具时,它是未定义的。
【问题讨论】:
-
使用 rest 运算符而不是在那里写所有参数。使用三元运算符进行空检查,并确保将名称传递到此无状态组件中
标签: reactjs material-ui redux-form