Skip to main content
Version: 3.xx.xx

on-search-live-preview

localhost:3000
Live previews only work with the latest documentation.
import {
Autocomplete,
useAutocomplete,
TextField,
} from "@pankod/refine-mui";

interface ICategory {
id: number;
title: string;
}

const PostCreate: React.FC = () => {
const { autocompleteProps } = useAutocomplete<ICategory>({
resource: "categories",
onSearch: (value) => [
{
field: "title",
operator: "contains",
value,
}
]
});

return (
<Autocomplete
{...autocompleteProps}
getOptionLabel={(item) => item.title}
isOptionEqualToValue={(option, value) =>
value === undefined || option?.id?.toString() === (value?.id ?? value)?.toString()
}
placeholder="Select a category"
renderInput={(params) => (
<TextField
{...params}
label="Category"
margin="normal"
variant="outlined"
required
/>
)}
/>
);
};