【发布时间】:2018-08-15 02:21:10
【问题描述】:
当我从 react-bootstrap 尝试这个示例代码时,我不断收到错误,例如“参数‘上下文’隐式具有‘任何’类型;“属性‘值’不存在于类型‘只读’上。”
在 form.tsx 中:
class FormExample extends React.Component {
constructor(props, context) {
super(props, context);
this.handleChange = this.handleChange.bind(this);
this.state = {
value: ''
};
}
getValidationState() {
const length = this.state.value.length;
if (length > 10) return 'success';
else if (length > 5) return 'warning';
else if (length > 0) return 'error';
return null;
}
handleChange(e) {
this.setState({ value: e.target.value });
}
render() {
return (
<form>
<FormGroup
controlId="formBasicText"
validationState={this.getValidationState()}
>
<ControlLabel>Working example with validation</ControlLabel>
<FormControl
type="text"
value={this.state.value}
placeholder="Enter text"
onChange={this.handleChange}
/>
<FormControl.Feedback />
<HelpBlock>Validation is based on string length.</HelpBlock>
</FormGroup>
</form>
);
}
}
export default FormExample;
在 Jumbo.tsx 中:
const Jumbo = () => (
<FormExample />
);
【问题讨论】:
标签: twitter-bootstrap reactjs typescript redux