Created
January 21, 2018 19:15
-
-
Save jamesplease/f025c2d69a5195b36dc59e35bb0be24a 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 { connect } from 'react-redux'; | |
import { bindActionCreators } from 'redux'; | |
import { readBook } from '../redux/books/action-creators'; | |
class App extends Component { | |
render() { | |
const { isFetchingBook, book } = this.props; | |
return ( | |
<div> | |
{isFetchingBook && 'Loading book...'} | |
{!isFetchingBook && ( | |
<div> | |
<h1>{book.title}</h1> | |
<h2>{book.author}</h2> | |
</div> | |
)} | |
</div> | |
); | |
} | |
componentDidMount() { | |
this.props.readBook(this.props.bookId); | |
} | |
} | |
function mapStateToProps(state, props) { | |
return { | |
isFetchingBook: state.books.fetching, | |
book: state.books.resources[props.bookId] | |
}; | |
} | |
function mapDispatchToProps(dispatch) { | |
return bindActionCreators( | |
{ | |
readBook | |
}, | |
dispatch | |
); | |
} | |
export default connect(mapStateToProps, mapDispatchToProps)(App); |
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 { ReadBook } from '../request-components/books'; | |
class App extends Component { | |
render() { | |
return ( | |
<ReadBook | |
bookId={this.props.bookId} | |
render={() => { | |
return ( | |
<div> | |
{isFetchingBook && 'Loading book...'} | |
{!isFetchingBook && ( | |
<div> | |
<h1>{book.title}</h1> | |
<h2>{book.author}</h2> | |
</div> | |
)} | |
</div> | |
); | |
}} | |
/> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment