Skip to content

Instantly share code, notes, and snippets.

@vladinator1000
Created February 4, 2018 22:24
Show Gist options
  • Save vladinator1000/68689045bf42ebe2f1d0ab935d09321b to your computer and use it in GitHub Desktop.
Save vladinator1000/68689045bf42ebe2f1d0ab935d09321b to your computer and use it in GitHub Desktop.
import * as React from 'react';
import {
Table,
Search,
} from 'semantic-ui-react';
import { Venue } from '../redux/types';
export interface Props {
getVenuesByName: (name: string) => [Venue];
}
function debounce(func: any, waitMilliseconds: number = 250) {
let timer: number;
return () => {
window.clearTimeout(timer);
timer = window.setTimeout(() => func(), waitMilliseconds);
};
}
export default class Venues extends React.Component<Props, object> {
constructor(props: Props) {
super(props);
this.search = this.search.bind(this);
}
async search(event: React.SyntheticEvent<HTMLInputElement>, { value }: any) {
try {
const venues = await this.props.getVenuesByName(value);
console.log(venues);
} catch (error) {
console.error(error);
}
}
render() {
return [
<Search
key="search"
showNoResults={false}
onSearchChange={debounce(this.search)}
/>,
<Table>
...
</Table>
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment