Currently, I am developing a small application using react-redux and material-ui. However, I have encountered an issue with the autocomplete field while implementing the onNewRequest property. Instead of triggering when I select an element from the list, it behaves like an onClick event for the component.
Here is a snippet of the code:
const test = () => {
alert("Something");
}
The component relies on a service response to display the data as follows:
case Status.OK:
return <AutoComplete
floatingLabelText="Origin"
filter={(searchText, key) => (searchText.length >= 3 && key.indexOf(searchText) !== -1)}
dataSource={ renderOrigins(response.data) }
openOnFocus={false}
maxSearchResults={3}
onNewRequest={ test() }
onClick={onClick(dispatch)}
style={{marginRight: '30px'}}
/>
In essence, the problem lies in the fact that the function test() gets executed when selecting the autocomplete field, rather than when choosing an item from the list.
Best regards.