Last active
January 30, 2018 23:21
-
-
Save pinkmomo027/fddb38c420ab368aa1ddfa92fc8d8459 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
class ColorCard extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = {color: ''}; | |
this.handleSubmit = this.handleSubmit.bind(this); | |
// this.handleChange = this.handleChange.bind(this); | |
} | |
handleSubmit(e) { | |
this.setState({color: this.input.value}); | |
this.input.value = ''; | |
this.input.focus(); | |
e.preventDefault(); | |
} | |
// handleChange(e) { | |
// this.setState({color: e.target.value}); | |
// } | |
render() { | |
let squareStyle = { | |
width: 200, | |
height: 200, | |
border:'1px solid grey', | |
marginBottom: 10, | |
backgroundColor: this.state.color | |
} | |
let buttonStyle = { | |
marginLeft: 6, | |
borderRadius: 4, | |
} | |
return ( | |
<div> | |
<div style={squareStyle}> | |
</div> | |
<form onSubmit={this.handleSubmit} ref='form'> | |
<input | |
type='text' | |
placeholder='enter color here' | |
ref={ el => this.input = el} /> | |
<button type='submit' style={buttonStyle} >Go</button> | |
</form> | |
</div> | |
) | |
} | |
} | |
ReactDOM.render(<ColorCard />, document.querySelector('#root')); | |
// HTML | |
// <div id='root'></div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment