I'm creating a Search input that uses lodash debounce
to delay the requests when typing.
constructor(props) {
super(props);
this.state = {
query: ""
};
this.debouncedFetchSearchList = debounce(this.fetchSearchList, 500);
}
These are the functions I use to fetch the list:
fetchSearchList = (query: string) => {
if (query.length >= 3) {
this.props.setSearchList(query);
}
};
updateQuery = (id: string, value: string) => {
const query = value;
this.setState({
query: query
});
this.debouncedFetchSearchList(query);
};
JSX:
<TextInput
type="text"
id="search-items"
onChange={this.updateQuery}
label={I18n.search}
placeholder={I18n.search}
className="search-items"
/>
When I type using this setup I get the error: "Uncaught TypeError: _this.debouncedFetchSearchList is not a function"
If I call console.log(this) I can see that the function is there and it's value is a lodash wrapper.
Am I missing something obvious?