Last active
June 27, 2018 11:51
-
-
Save cartant/046444720e88e1804f28cec566da91f3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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