Created
April 1, 2019 10:45
-
-
Save webpapaya/b4aced240e74e41288d2387008fd08bc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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