0

I am looking at this source code.

render() {
    const { value, onChange, options } = this.props

    return (
      <span>
        <h1>{value}</h1>
        <select onChange={e => onChange(e.target.value)}
                value={value}>
          {options.map(option =>
            <option value={option} key={option}>
              {option}
            </option>)
          }
        </select>
      </span>
    )
  }

my question is, why the event handler is onChange? I think the standard html attribute is onchange. and unfortunately, I cannot find any react document about the event handler names

thanks

2 Answers 2

1

Firstly, HTML attributes are case insensitive, so onchange, onChange and ONCHANGE are all equivalent in HTML.

However, JSX is not HTML. In React, case is important, so onChange it must be.

The select element in React also differs in other ways from the select element in HTML. For instance, value is defined on the select element, making the selected attribute on the option element obsolete.

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

Comments

0

Event is defined as onChange in ReactJS: https://facebook.github.io/react/docs/events.html

You have some examples of use in ReactJS documentation website: https://facebook.github.io/react/docs/forms.html

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.