약간의 대화방을 만들고 있습니다. application.i는 Material UI TextField를 사용하여 사용자 메시지를 입력했습니다. 하지만 나는 그것을 언급 할 수 없다. 나는 이것에 관해 읽었다. 그들은 refs
을 지원하지 않는다고 말했다. 이것은 내 코드입니다. 작동합니다.재질 UI 구성 요소 참조가 작동하지 않습니다.
class App extends Component {
constructor() {
super();
this.state = {
q: "default"
};
}
handleChanges(val) {
this.setState({ q: val });
}
handleSearch(val) {
this.setState({ q: val });
console.log(this.state.q);
}
render() {
return (
<div className="App">
<h1> {this.state.q}</h1>
<Row className="show-grid">
<Col sm={2} md={4} className="contact"><h5>contact</h5><br /></Col>
<Col sm={10} md={8} className="chat grid-border"><h5>chat</h5><br />
<div className="history"></div>
<div className="message top-border">
<input type="text" ref="question" onChange={(e) => { this.handleChanges(this.refs.question.value) }} />
<MuiThemeProvider>
<FlatButton label="Primary" primary={true} onTouchTap={(e) => { e.preventDefault(); this.handleSearch(this.refs.question.value); }} />
</MuiThemeProvider>
</div>
</Col>
</Row>{/*show-grid ends here*/}
</div>
);
}
}
export default App;
나는 물질이 UI TextField
대신 기본 HTML 입력 태그를 사용하는 경우는, 기준의 값을 얻을 수 없다.
<MuiThemeProvider>
<TextField hintText="Ask your question" fullWidth={true} multiLine={true} rows={2} rowsMax={4} type="text" ref="question" onChange={(e) => { this.handleChanges(this.refs.question.value) }}/>
</MuiThemeProvider>
이에 대한 대안 또는 대안 UI 라이브러리가 있습니까?
노력해 주셔서 감사합니다. – IsuruAb
좋은 해결책. 다른 요소를 추가하면 같은 방법으로는 작동하지 않습니다. 중복 된 방법을 써야합니다. refs를 사용하면 두 개의 TextField에 대해 ref = "a"및 ref = "b"가 주어 지므로 setState 메서드에서 this.refs.a.value 및 this.refs.b.value를 확인할 수는 있지만 작동하지 않습니다. Material UI가 있습니다. –