r/learnreactjs • • Jun 12 '22

In Material-Table editComponent issue

in my code down below for some reason setCity keeps on re rendering continuasuly when I just type in once into the autocomplete and then I don't have the ability to keep typing.

let cityValue = useRef("")

 

      const [city,setCity] = use State([])

 

      async function getCities(value){

          cityValue.current = value

          console.log("herrrrrr")

          let searchResult =await ApiService.loadDestinations(value)

          let newSearch = searchResult.map((e)=>{return e.name})

          console.log("newSearch",newSearch)

         setCity(newSearch)

      }

 

      const columns = [

          { title:"Street",

          field:"street"},

         { title:"Cluster",

            field:"cluster"},

 

       

        {

            title:"City",

            field:"city",

            editComponent:props =>(

 

                <Autocomplete value={cityValue.current} options = {city} onInputChange = {(event,value) => getCities(value)}  renderInput = {(params) => <TextField   {...params} />} />

 

            ),

 

        },
2 Upvotes

0 comments sorted by