I am having problems with redux. I'm trying to dispatch a value from a search bar I created that will get the client ID of who I type in. The auto-suggestion works fine. The Item (ID Number) and value (Client name) correctly in the console log. but I am unable to dispatch it to the reducer. I keep getting a "dispatch" is not a function error. Redux is imported. Any Ideas?
class ClientSearch extends Component {
constructor(props){
super(props)
this.state = {
}
lowerCase = (str) => {
console.log(str);
return str;
}
test = (value, item) => {
console.log('Inside Test',item.numClientID);
let { dispatch } = this.props
dispatch(fetchClient(item.numClientID))
}
}
render() {
let value = '';
return (
<div>
<ReactAutocomplete
items={this.props.clients}
shouldItemRender={(item, value) => item.txtName.toLowerCase().indexOf(value.toLowerCase()) > -1}
getItemValue={(item) => item.txtName}
renderItem={(item, highlighted) =>
<div
key={item.numClientID}
style={{ backgroundColor: highlighted ? 'purple' : 'transparent'}}
>
{item.txtName}
</div>
}
value={this.state.selectedClient}
onChange={e => this.setState({ selectedClient: e.target.value })}
onSelect={(value, item) => this.test(value,item)}
/>
</div>
);
}
}
const mapStateToProps = (state) => {
console.log('map state', state)
return {
clients: state.client.clients
};
};
export default connect(mapStateToProps, dispatch =>
bindActionCreators(listClients, dispatch, fetchClient, dispatch)
)(ClientSearch);