0

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?

1 Answer 1

2

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!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.