按下回车按钮并过滤数据
按下回车按钮并过滤数据
我正在实现筛选数据的功能。以下代码是即时搜索功能。是否有办法在按下回车键后显示结果?也就是说,只有按下回车键用户才能看到结果。\n
import React, { Fragment } from "react"; import { TextField, makeStyles } from "@material-ui/core"; const useStyle = makeStyles((theme) => ({ inputRoot: { backgroundColor: "white", borderRadius: 10, }, inputInput: { padding: theme.spacing(1, 1, 1, 2), transition: theme.transitions.create("width"), width: "100%", [theme.breakpoints.up("md")]: { width: 80, }, }, })); const SearchBox = ({ onSubmit }) => { const classes = useStyle(); const [formData, setFormData] = React.useState({ keyword: "", }); const { keyword } = formData; const handleChange = (keyword) => (e) => { setFormData({ ...formData, [keyword]: e.target.value }); }; onSubmit(keyword); return (); }; export default SearchBox;