npm

reactform

1.0.81 • Public • Published
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>
        );
    }
 
}

Package Sidebar

Install

npm i reactform

Weekly Downloads

8

Version

1.0.81

License

MIT

Last publish

Collaborators

  • ergusto