0

I'm trying to get the value of the inner input element but every time I got this error:

Uncaught TypeError: this.containerInput.gatValue is not a function

What am

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

2
  • Well you obviously have a typo. "gatValue" should be "getValue". Commented Dec 22, 2020 at 0:09
  • Yeah, probably that was the case. I feel ashamed of that question, 4 years ago 😥 Commented Dec 30, 2020 at 16:23

1 Answer 1

2

Did you mean this.containerInput.getValue() or this.containerInput.textInput.value ?

Sign up to request clarification or add additional context in comments.

1 Comment

Actually it works with this.viewInput.containerInput.getValue();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.