osstotalsoft / rocket-ui-ts

A collection of reusable and composable React components written in TypeScript built on top of Material UI Core V5
MIT License
19 stars 4 forks source link

Add prop to preserve search input of multiselect autocomplete #102

Open Boerescu-Razvan opened 10 months ago

dragos-rosca commented 4 months ago
const MyComponent() {
 const [value, setValue] = useState([])

 const [input, setInput] = useState('')
 const handleInputChange = useCallback((_event, value, reason) => {
  if (reason === 'input') setInput(value)
 }, [])

 const {data, loading} = useQuery(YOUR_QUERY, { variables: { input }})

 return (
  <Autocomplete
   value={value}
   onChange={setValue}

   inputValue={input}
   onInputChange={handleInputChange}

   options={data?.options || []}
   loading={loading}
  />
 )
}

how is this not a viable option?