Fubundzer
Fubundzer

Reputation: 75

Passing parameter to material-ui AutoComplete

is there any way to pass additional parameters to function in material-ui's AutoComplete component? I would like to pass something beside value in onUpdateInput tag. Here's what I want to do but in normal React version: https://reactjs.org/docs/handling-events.html#passing-arguments-to-event-handlers

Here's my code

{this.state.members.map((member, idx) => (
     <div className="member">
     <AutoComplete
          type="text"
          name="members[]"
          hintText={`Member name`}
          filter={AutoComplete.caseInsensitiveFilter} 
          dataSource={this.state.dataSource}
          onUpdateInput={this.handleInputUpdate}
     />
     <button type="button" onClick={this.handleRemoveMember(idx)}className="small">-</button>
     </div>
 ))}

Now I would like to pass 'idx' to handleInputUpdate function. Can I do this somehow?

Upvotes: 0

Views: 1527

Answers (1)

MEnf
MEnf

Reputation: 1522

I'm not familiar with the material-ui library, but you can add your own parameters to a function by using callbacks.

handleInputUpdate = (x, y, idx) => {
  //code goes here
}

...

 onUpdateInput={(x, y) => this.handleInputUpdate(x, y, idx)}

in this example, x and y are parameters from the onUpdateInput function that you want to use in your function.
Then you provide your own parameter, like idx, into the handleInputUpdate function.

Hope this helps!

Upvotes: 2

Related Questions