Created
February 23, 2018 21:44
-
-
Save npverni/7b6f300aea0535c84bb6e0e725f89162 to your computer and use it in GitHub Desktop.
This file contains 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, { Component } from 'react'; | |
import './App.css'; | |
class App extends Component { | |
state = { | |
focused: '', | |
} | |
setFocus = field => this.setState({ focused: field }); | |
unsetFocus = () => console.log("Unsetting focus"); | |
isFocused = field => (this.state.focused === field); | |
render() { | |
return ( | |
<div className="App"> | |
<div> | |
<label>Name</label> | |
<input | |
type="text" | |
onFocus={() => this.setFocus('name')} | |
onBlur={this.unsetFocus} | |
/> | |
<small>{this.isFocused('name') && "Focused on name"}</small> | |
</div> | |
<div> | |
<label>Age</label> | |
<input | |
type="text" | |
onFocus={() => this.setFocus('age')} | |
onBlur={this.unsetFocus} | |
/> | |
<small>{this.isFocused('age') && "Focused on age"}</small> | |
</div> | |
</div> | |
); | |
} | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment