Created
February 4, 2018 22:24
-
-
Save vladinator1000/68689045bf42ebe2f1d0ab935d09321b 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 { | |
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