You get a bonus - 1 coin for daily activity. Now you have 1 coin

What are uncontrolled components? in REACT

Practice



In React, Uncontrolled Components are those that keep their state internally, and you query the DOM using a ref to find its current value when you need it. This is a little closer to traditional HTML.

In the UserProfile component below, the

name
input is accessed with a ref.
class UserProfile extends React.Component {
  constructor(props) {
    super(props)
    this.handleSubmit = this.handleSubmit.bind(this)
    this.input = React.createRef()
  }

  handleSubmit(event) {
    alert('A name was submitted: ' + this.input.current.value)
    event.preventDefault()
  }

  render() {
    return (
      <form onSubmit={this.handleSubmit}>
        <label>
          {'Name:'}
          <input type="text" ref={this.input} />
        </label>
        <input type="submit" value="Submit" />
      </form>
    );
  }
}

In most cases it is recommended to use controlled components to implement forms.

Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Scripting client side JavaScript, jqvery, BackBone"

Terms: Scripting client side JavaScript, jqvery, BackBone