Skip to content

Instantly share code, notes, and snippets.

@cartant
Last active June 27, 2018 11:51
Show Gist options
  • Select an option

  • Save cartant/046444720e88e1804f28cec566da91f3 to your computer and use it in GitHub Desktop.

Select an option

Save cartant/046444720e88e1804f28cec566da91f3 to your computer and use it in GitHub Desktop.
import * as React from "react";
import { componentFromStream, createEventHandler } from "recompose";
import { from } from "rxjs";
import { debounceTime, distinctUntilChanged, map, startWith } from "rxjs/operators";
export const SomeComponent = () => {
const { handler, stream } = createEventHandler();
const SearchingComponent = componentFromStream(props => from(stream).pipe(
map(event => event.target.value),
debounceTime(400),
distinctUntilChanged(),
startWith(""),
map(term => !term ? null : (
<div className="searching">
<span>Searching for {term}</span>
</div>
))
);
return (<>
<input onChange={handler} type="text"/>
<SearchingComponent/>
</>);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment