Created
March 15, 2018 18:13
-
-
Save frankfaustino/fd6323a83999996bbe1ffef37ac13e87 to your computer and use it in GitHub Desktop.
React: Separate stateful aspects from rendering
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
// Container Pattern: https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0 | |
import Loading from './Loading' | |
import RenderUser from './RenderUser' | |
class User extends Component { | |
state = { loading: true } | |
render() { | |
const { loading, user } = this.state | |
return loading ? <Loading /> : <RenderUser user={user} /> | |
} | |
componentDidMount() { | |
fetchUser(this.props.id) | |
.then(user => { this.setState({ loading: false, user })}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment