I am trying to replicate the debounceTime functionality from rxjs. I saw this example from Angular:
fromEvent(this.input.nativeElement, 'keyup')
.pipe(
map(event => event.target.value),
debounceTime(400),
distinctUntilChanged(),
)
.subscribe(val => console.log(val));
My replication in react native:
export default function SearchScreen() {
const [text, setText] = useState('');
function onChangeHandler(event) {
of(event)
.pipe(
map(event => event.nativeEvent.text),
debounceTime(400),
)
.subscribe(val => console.log(val));
}
return (
<View>
<View>
<TextInput
value={text}
onChangeText={text => setText(text)}
onChange={onChangeHandler}
/>
</View>
</View>
);
}
But I could not find a way to use fromEvent. Instead I used the of.
But the debounceTime is not working.