import React, { Component } from 'react'; import { debounce } from 'lodash'; export interface Props { onChange: (alignmentPeriod) => void; value: string; } export interface State { value: string; } export class AliasBy extends Component { constructor(props) { super(props); this.updateQuery = debounce(this.updateQuery.bind(this), 500); this.state = { value: '' }; } componentDidMount() { this.setState({ value: this.props.value }); } componentWillReceiveProps(nextProps: Props) { if (nextProps.value !== this.props.value) { this.setState({ value: nextProps.value }); } } onChange(e) { this.setState({ value: e.target.value }); this.updateQuery(e.target.value); } updateQuery(value) { this.props.onChange(value); } render() { return (
this.onChange(e)} />
); } }