我的原始代码是这样的:
handleClick() {
var name = this.refs.name.value;
var description = this.refs.description.value
}
render () {
return (
<React.Fragment>
<input ref='name' placeholder='Enter the name of the item' />
<input ref='description' placeholder='Enter a description' />
<Button onClick={this.handleClick.bind(this)}>Submit</Button>
</React.Fragment>
);}
name
和description
可以正确获取输入。
但是当我使用<TextField>
时:
<TextField ref='name' placeholder='Enter the name of the item' />
它表明传递的值为null
,似乎ref
不起作用。
有人能帮我解决这个问题吗?