React Native _this2.refs.myinput.focus is not a function

Using React-Native, I have a custom component that extends from TextInput as follows:

Textbox.js

...
render() {
  return (
  <TextInput
    {...this.props}
    style={styles.textBox}/>
  );
}
...

MyScene.js (imports TextBox.js)

...
render() {
  render(
    <View>
      <TextBox
        rel='MyFirstInput'
        returnKeyType={'next'}
        onSubmitEditing={(event) => { this.refs.MySecondInput.focus(); }}/>

      <TextBox
        ref='MySecondInput'/>
    </View>
  );
}

When I create an application and press further on the keyboard, when I focus on MyFirstInput, I expect it to MySecondInputbe in focus, instead I get an error:

_this2.refs.MySecondInput.focus is not a function

What could be a mistake? Is it related to volume this? Thank.

+4
source share
3 answers

This is because the focus is the TextInput method, and it is not in the advanced version.

TextBox.js, :

focus() {
    this.refs.textInput.focus();
},

TextInput

render() {
  return (
  <TextInput
    {...this.props}
    ref={'textInput'}
    style={styles.textBox}/>
  );
}
+8

, ref HTML? , - , : , , , , .focus HTML-?

MDN. , HTML, , ref MySecondInput , ?

+1

React,

ref = { ref => this._randomName = ref }

,

this._randomName.anyMethod()
0

Source: https://habr.com/ru/post/1657820/


All Articles