这是我用于搜索选项的代码,它在单击输入按钮时起作用,但是在单击输入时不起作用。我尝试了此代码,但无法正常工作。
import React, { Component } from "react";
import {Row, Col, InputGroupAddon, InputGroup, InputGroupText, Input, Card, CardHeader, CardBody, ButtonDropdown, DropdownToggle, DropdownMenu, DropdownItem, Button} from "reactstrap";
import {Link} from 'react-router-dom'
export default class Search extends Component {
constructor(props) {
super(props);
};
}
Find(e) {
this.setState({ search: e.target.value }) //=====SETTING ENTERED VALUE TO A STATE======//
}
enterPress(e) {
e.preventDefault()
this.props.history.push('/events')
}
render() {
return (
<div>
<Input type="text" id="input1-group1" name="input1-group1" placeholder="Search for events and places" onChange={this.Find.bind(this)} onKeyPress={this.enterPress.bind(this)}/>
</div>
);
}
}
该代码在单击“搜索”时是正确的,但在按Enter时不起作用。我收到此代码的未定义错误。