Skip to content

Instantly share code, notes, and snippets.

@arminyahya
Last active July 5, 2019 15:16
Show Gist options
  • Save arminyahya/3460a4de95c941aca7f37171248f765d to your computer and use it in GitHub Desktop.
Save arminyahya/3460a4de95c941aca7f37171248f765d to your computer and use it in GitHub Desktop.
form with observer
import React from 'react';
import LoginFormState from './formstate';
import { Observer } from 'mobx-react';
const LoginForm = () => {
const formData = new LoginFormState();
return (
<Observer>
{() => {
return (
<div className="login-form">
<div className="login-form_field">
<label>username</label>
<input onChange={(e) => { formData.username.onChange(e.target.value); }} />
</div>
<div className="login-form_field">
<label>password</label>
<input onChange={(e) => { formData.password.onChange(e.target.value); }} />
</div>
<button type="button" onClick={formData.onSubmit}>submit</button>
</div>)
}}
</Observer>
);
}
export default LoginForm;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment