我正在使用React JS,但不知道为什么会出现“props未定义”的错误。
这是我的类代码:
import React, { Component } from 'react';
const InputHeight = {
height: '50px',
}
function clearData() {
this.refs.input.value = "";
}
export default class TextInput extends Component {
render() {
return (
<input
className="form-control"
ref="input"
name={props.name}
type={props.inputType}
value={props.content}
pattern={props.pattern}
onChange={props.controlFunc}
placeholder={props.placeholder}
style={InputHeight}
required />
);
}
}
TextInput.propTypes = {
inputType: React.PropTypes.oneOf(['text', 'number', 'email']).isRequired,
name: React.PropTypes.string.isRequired,
controlFunc: React.PropTypes.func.isRequired,
content: React.PropTypes.oneOfType([
React.PropTypes.string,
React.PropTypes.number,
]).isRequired,
placeholder: React.PropTypes.string,
};
编译失败 ./src/components/Parts/SmallBits/FormItems/TextInput.js 第19行: 'props' 未定义 no-undef 第20行: 'props' 未定义 no-undef 第21行: 'props' 未定义 no-undef 第22行: 'props' 未定义 no-undef 第23行: 'props' 未定义 no-undef 第24行: 'props' 未定义 no-undef 搜索关键词以了解有关每个错误的更多信息。
this.refs.form.clearData();
只需点击它,它就会给我
未捕获的类型错误:无法读取 null 的属性“refs”