0
私は内側のinput要素の値が、私はこのエラーまし毎回取得しようとしている:reactjsと内部コンポーネントからの入力の値を取得します
Uncaught TypeError: this.containerInput.gatValue is not a function
だ何
class Input extends Component {
getValue() {
return this.textInput.value;
}
render() {
return (
<input type="text" ref={(input) => this.textInput = input} />
);
}
}
class Container extends Component {
getValue() {
return this.containerInput.gatValue();
}
render() {
return (
<Input ref={(input) => this.containerInput = input} />
);
}
}
class View extends Component {
constructor(props) {
super(props);
this.buttonClick = this.buttonClick.bind(this);
}
buttonClick(e) {
console.log(this.viewInput.getValue());
}
render() {
return (
<div>
<Container ref={(input) => this.viewInput = input} />
<button onClick={this.buttonClick}>Get Value</button>
<span></span>
</div>
);
}
}
ReactDOM.render(
<View />,
document.getElementById('root')
);
DEMOを
実際には、this.viewInput.containerInput.getValue()で動作します。 –