我正在使用 Material UI 库实现组件自动完成。
但有一个问题 - 我不确定如何正确传递 value 和 onChange,因为我有一个 TextField 的自定义实现,它也需要 value 和 onChange。我应该将 value 和 onChange 传递两次 - 到 Autocomplete 和 TextField 吗?或者也许有更好的解决方案?将不胜感激任何帮助!这是我的代码:
import { Autocomplete as MuiAutocomplete } from '@material-ui/lab'
import { FormControl } from 'components/_helpers/FormControl'
import { useStyles } from 'components/Select/styles'
import { Props as TextFieldProps, TextField } from 'components/TextField'
export type Props = Omit<TextFieldProps, 'children'> & {
options: Array<any>
value: string
onChange: (value: string) => void
disabled?: boolean
}
export const Autocomplete = (props: Props) …Run Code Online (Sandbox Code Playgroud)