【发布时间】:2020-04-26 02:41:42
【问题描述】:
我原来的代码是这样的:
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不起作用。
谁能帮我解决这个问题?
【问题讨论】:
标签: material-ui textfield ref