skip to Main Content

I am trying to strip part of a string in react native. And I am getting an error saying that String.slice() method cannot read from an undefined.

<TextInput style={styles.largeFormInput}
onChange={(event) => {

          let value = event.target.value;
          setBio(value.slice(0, 10));
        }}

        value={bio} name={"bio"}
        placeholder={"Brief Biography (i.e. hobbies, family life, welness tools & programs that work for you)"} placeholderStyle={styles.placeholderStyle} />

{/* was expecting the string to strip correctly and it works fine on web, but it does not work on my expo go simulator */}

3

Answers


  1. There’s no onChange listener in TextInput.

    You should be using onChangeText={text => onChangeText(text)} as per
    ref-doc

    Login or Signup to reply.
  2. try use onChangeText instead of onChange

    Login or Signup to reply.
  3. The event.target.value is undefined. You have to use onChangeText

    onChangeText={(value) => setBio(value.slice(0, 10))}
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search