пользовательский компонент не фокусируется на следующем вводе текста на SubmitEditting - PullRequest
1 голос
/ 27 мая 2020

Я использовал перехватчики реакции. Когда я нажимаю кнопку «Следующая», я получаю сообщение об ошибке, например, что undefined не является объектом (оценка nextRef.focus).

 const renderRow = (value, onUpdate, currentRef, nextRef) => {
    return (
          <View style={VALUE_CONTAINER}>
            <TextField
              autoCorrect={false}
              onChangeText={(text) => onUpdate(text)}
              autoCapitalize={"none"}
              returnKeyType={'next'}
              onSubmitEditing={() => { nextRef.current.focus() }}
              forwardedRef={(input) => { currentRef = input }}
              value={value} />
          </View>
    )
  }

Я вызываю этот компонент из основного представления следующими строками

        {renderRow(mobile, updateMobile, mobileRef, cityRef)}
        {renderRow( city, updateCity, cityRef, mobileRef)}

1 Ответ

1 голос
/ 27 мая 2020

Вместо того, чтобы назначать ref для currentRef.current, вы назначили его для currentRef, поэтому это может вызвать проблему

const renderRow = (value, onUpdate, currentRef, nextRef) => {
    return (
          <View style={VALUE_CONTAINER}>
            <TextField
              autoCorrect={false}
              onChangeText={(text) => onUpdate(text)}
              autoCapitalize={"none"}
              returnKeyType={'next'}
              onSubmitEditing={() => { nextRef.current.focus() }}
              forwardedRef={(input) => { currentRef.current = input }}
              value={value} />
          </View>
    )
  }
...