Created
March 30, 2016 12:24
-
-
Save xie-qianyue/b446997dee3351dc6a82b5849fec27ef to your computer and use it in GitHub Desktop.
React container component
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
class TodoContainer extends Component { | |
componentDidMount() { | |
this.setState({ isLoding: true }); | |
fetch('/todos.json').then( | |
todos => { | |
this.setState({ | |
error: null, | |
todos, | |
isLoding: false | |
}); | |
}, | |
error => this.setState({ error }) | |
); | |
} | |
render() { | |
return <Todo {...this.state} /> | |
} | |
} | |
class Todo extends Component { | |
render() { | |
const { error, isLoding, todos } = this.props; | |
if(error) { | |
return <ErrorPage />; | |
} | |
if(isLoding) { | |
return <Spinner />; | |
} | |
if(!todos.length) { | |
return <EmptyResult />; | |
} | |
const lists = todos.map(todo => { | |
return <TodoItem {...todo} />; | |
}); | |
return <ul> {lists} </ul>; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment