I want to create an observable from a change event that gets fired on a React Native TextInput
component. TextInput
comes with 2 change props that I'm aware of (onChangeText
and onChange
). From what I gather, you need to use onChange
if you want access to the native event you need to use onChange
.
I don't know much about the native event object. I am trying to create an rxjs observable using fromEvent
.
First I created a ref in my functional component like this:
const sqftRef = useRef().current
Then I attached this ref to the TextInput
component like this:
<TextInput
ref={sqftRef} // attach a ref
label='Sqft'
mode='flat'
textContentType='none'
autoCapitalize='none'
keyboardType='numeric'
autoCorrect={false}
value={String(formValues.sqft)}
dense
underlineColor={colors.colorOffWhite}
onChangeText={(text) => setText(text)}
onChange={e => {
// somehow create an observable from this event ???
}}
style={styles.inputStyles}
theme={inputTheme}
/>
I tried to create an Observable using fromEvent like this but it doesn't work. I get undefined is not an object (evaluating target.addEventListener):
fromEvent(sqftRef, 'onChange').subscribe(value => console.log(value))
I know my approach is all wrong. Hoping someone can point me in the correct direction.