NewProgrammer
NewProgrammer

Reputation: 164

Using event in react

So what i'm trying to do is when someone clicks an option I want to send two arguments during the onChange invocation. How can I manage to send the event and a second argument? I can think of a way to solve this problem that wouldn't require me to send the second argument, but I want to know if there is anyway I can send the event and another argument.

      {this.state.watchedMovies.map((movie, index) => (
          <div className="txn-row" key={index}>
                <div className="txn-data">{movie.moviename}</div>

                <div className="txn-data">
                    <select className="scorebar" onChange={() => this.changescore(event, movie)}>
                    <option>{movie.score > 10 ? <span>Rate</span> : movie.score}</option>
                    {this.state.grades.map((grade, index) =>(
                        <option value={grade} key={index}>{grade}</option>
                    ))}
                    </select>
                </div>

          </div>
      ))}

Upvotes: 1

Views: 63

Answers (1)

Tholle
Tholle

Reputation: 112787

The function given to onChange will be invoked with the event as first argument, so you need to pass that along to your changescore method.

<select
  className="scorebar"
  onChange={(event) => this.changescore(event, movie)}
>

Upvotes: 2

Related Questions