how to set dynamic autocomplete with material ui 1

how to set dynamic autocomplete with material ui

 import React, { useState } from 'react';
using useState:

   const [val,setVal]=useState({})
changin value on click of button

  const handleClick = () => {
    setVal(top100Films[0]);//you pass any value from the array of top100Films
   // set value in TextField from dropdown list
 };
and pass this value to component in render

  option.title}
    style={{ width: 300 }}
    renderInput={params => (
      
    )}
  />

Here is what the above code is Doing:
1. We’re using the useState hook to create a state variable called val and a function to update it called setVal.
2. We’re passing the value of val to the Autocomplete component.
3. We’re passing the setVal function to the onChange prop of the Autocomplete component.
4. We’re passing the value of val to the TextField component.
5. We’re passing the setVal function to the onChange prop of the TextField component.

Similar Posts