Skip to content

Instantly share code, notes, and snippets.

@webpapaya
Created April 1, 2019 10:45
Show Gist options
  • Save webpapaya/b4aced240e74e41288d2387008fd08bc to your computer and use it in GitHub Desktop.
Save webpapaya/b4aced240e74e41288d2387008fd08bc to your computer and use it in GitHub Desktop.
import React, { useState } from 'react';
const Button = ({ children, variant = 'button' }) => {
return (
<button style={{ background: variant === 'button' ? 'blue' : 'green'}}>
{ children }
</button>
)
};
const Input = ({ value, onChange, label }) => {
return (
<input
type="text"
name={label}
placeholder={label}
value={value}
onChange={ onChange }
/>
)
}
const SignUp = ({}) => {
const [username, setUsername] = useState('');
const handleSubmit = (evt) => {
evt.preventDefault();
console.log({ username });
}
return (
<form onSubmit={handleSubmit}>
<Input
name="username"
placeholder="username"
value={username}
onChange={ (evt) => setUsername(evt.target.value.slice(0, 10)) }
/>
<Button variant='button'>Sign up</Button>
<Button variant='link'>Sign up</Button>
</form>
);
};
export default SignUp;
import React from 'react';
const Button = ({ children, variant = 'button' }) => {
return (
<button style={{ background: variant === 'button' ? 'blue' : 'green'}}>
{ children }
</button>
)
};
const Input = ({ value, onChange, label }) => {
return (
<input
type="text"
name={label}
placeholder={label}
value={value}
onChange={ onChange }
/>
)
}
class SignUp extends React.Component {
state = { username: '' };
setUsername = (evt) => setUsername(evt.target.value.slice(0, 10));
handleSubmit = (evt) => {
evt.preventDefault();
console.log({ username: this.state.username });
}
render() {
return (
<form onSubmit={this.handleSubmit}>
<Input
label="username"
value={this.state.username}
onChange={ this.setUsername }
/>
<Button variant='button'>Sign up</Button>
<Button variant='link'>Sign up</Button>
</form>
);
}
}
export default SignUp;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment