Skip to content

Instantly share code, notes, and snippets.

@StevenJL
Last active June 29, 2020 21:04
Show Gist options
  • Save StevenJL/c8f2d49066fccec8d1af559bf25ce0e5 to your computer and use it in GitHub Desktop.
Save StevenJL/c8f2d49066fccec8d1af559bf25ce0e5 to your computer and use it in GitHub Desktop.
class ControlledComponent extends React.Component {
constructor( props) {
super(props)
this.handleSubmit = this.handleSubmit.bind(this)
}
handleSubmit(event) {
event.preventDefault()
this.props.createAccount(
name: this.inputName.value,
email: this.inputEmail,value,
password: this.inputPassword.value
)
}
render() {
return (
<form onSubmit ={this.handleSubmit}>
<input type="text" name="name" ref={(node) => {this.inputName = node} defaultValue="Firstname Lastname" />
<input type="text" name="email" ref={(node) => {this.inputEmail = node} onChange={this.handleChange} defaultValue="[email protected]" />
<input type="password" name="password" ref={(node) => {this.inputPassword = node} onChange={this.handleChange} />
<button>Submit</button>
</form>
)
}
}
@juffalow
Copy link

You missed } in the end of each ref prop.

<input type="text" name="name" ref={(node) => {this.inputName = node}} defaultValue="Firstname Lastname" /> 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment