简体   繁体   中英

Get newly added object in Material-ui Autocomplete component

I'm using material-ui Autcomplete component with multiple selection. And for one of the scenario, I need to get the value for newly added item. When I'm using onChange listener, it is giving me all the values selected in Autocomplete input. Is there any way to get only added or removed one?

Codesandbox - https://codesandbox.io/s/xqex8?file=/demo.js

according to the doc, the onChange funct receive three properties, called event , value , and reason. You can receive the value of newly added item by taking advantage of event.target.textContent as below:

onChange={(event, value) =>
          console.log(
            top100Films.filter(
              (el, id) => el.title === event.target.textContent
            )
          )
        }

sandbox

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM