reactform
v1.0.81
Published
React form and input components with validation.
Downloads
28
Maintainers
Readme
Example login component.
import React, { Component } from 'react';
import { Redirect } from 'react-router-dom';
import { Form, TextInput, PasswordInput, Submit } from 'reactform';
import { login } from '../../lib/auth.js';
export default class Login extends Component {
constructor(props) {
super(props);
this.state = {
success: false
};
}
login = ({ username, password }) => {
login(username, password, (err, res) => {
if (res.ok) {
this.setState({ success: true });
}
});
};
render() {
const { success } = this.state;
if (success) {
return <Redirect to='/' />;
}
return (
<Form onSubmit={this.login}>
<TextInput required name='username' placeholder='username' validator={'alphanumeric'} />
<PasswordInput required name='password' placeholder='password' validator={'alphanumeric'} />
<Submit />
</Form>
);
}
}