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
There’s no
onChange
listener in TextInput.You should be using
onChangeText={text => onChangeText(text)}
as perref-doc
try use
onChangeText
instead ofonChange
The
event.target.value
isundefined
. You have to useonChangeText