【发布时间】:2017-08-26 13:29:49
【问题描述】:
似乎有很多错误的方法可以做到这一点,我相当肯定我正在尝试以错误的方式做到这一点(注意此代码目前不起作用):
class SubmitLink extends React.Component<SubmitLinkProps, {}>{
constructor(props: SubmitLinkProps) {
super(props);
this.urlToPass = "nothing";
}
urlToPass: string;
handleChange(e: React.FormEvent<HTMLInputElement>) {
this.urlToPass = e.currentTarget.value;
}
public render() {
return <div>
<div>hello world {this.props.url}</div>
<input onChange={this.handleChange} type='text'></input>
<button onClick={() => {
this.props.submitlink(this.urlToPass);
}}>submit</button>
</div>
}
}
除了代码不起作用(urlToPass 在运行时未定义,不确定原因)这一事实之外,为了从文本字段中获取输入,它看起来需要大量工作。同时,这是我在谷歌上搜索到的唯一方法,但它确实感觉不正确。
【问题讨论】:
标签: reactjs typescript react-redux