You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import { debounceTime, swtichMap } from 'rxjs'; - in useObservableState
and a question: Where does "getSearchResults(search)" come from?
import { useObservableState, useAsyncValues } from 'rxooks';
import { debounceTime, swtichMap } from 'rxjs';
function MyComp() {
// an observable of searches, and a setter to set the current search
const [searches, setSearch, getSearch] = useObservableState('');
// Here we're going to compose some reactivity using RxJS,
// and subscribe to the observable to get the search results out.
const searchResults = useAsyncValues(
() =>
searches.pipe(
debounceTime(500),
switchMap((search) => **getSearchResults(search))**
),
[searches] // deps
);
const searchResultCount = searchResults?.length ?? 0;
const hasSearchResults = searchResultCount > 0;
const searchChange = (e) => setSearch(e.target.value);
// Maybe there's some other side effect you'd like to do with the
// current value of the observable state. You can use the getter
// for that.
const submitForm = () => {
// Use the getter to get the most recent value
const lastSearch = getSearch();
doSomethingOnFormSubmit(lastSearch);
};
return (
<form onSubmit={submitForm}>
<div>
<label htmlFor="search-input">Search</label>
<input id="search-input" type="text" onChange={searchChange} />
</div>
{hasSearchResults && (
<ul>
{searchResults.map((result) => (
<li key={result.id}>{result.text}</li>
))}
</ul>
)}
</form>
);
}
The text was updated successfully, but these errors were encountered:
import { debounceTime, swtichMap } from 'rxjs'; - in useObservableState
and a question: Where does "getSearchResults(search)" come from?
import { useObservableState, useAsyncValues } from 'rxooks';
import { debounceTime, swtichMap } from 'rxjs';
function MyComp() {
// an observable of searches, and a setter to set the current search
const [searches, setSearch, getSearch] = useObservableState('');
}
The text was updated successfully, but these errors were encountered: