Last active
September 14, 2016 19:07
-
-
Save eashish93/f2d66c6aa32ce06f1cb7193623b71dbd to your computer and use it in GitHub Desktop.
React separating presentation and logic (smart-dumb 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
import React from 'react'; | |
import ReactDOM from 'react-dom'; | |
import SongsListContainer from './SongsListContainer'; | |
ReactDOM.render( | |
<SongsListContainer genre="^Bollywood" limit="8"/>, | |
document.getElementById('root') | |
); |
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 Request from 'superagent'; | |
// Logic (Smart) | |
class SongsListContainer extends Component { | |
constructor(props) { | |
super(props); | |
this.state = {meta: []} | |
} | |
componentDidMount() { | |
const url = 'http://localhost:3300/api/v1.0/'; | |
Request.get(`${url}albums`).query({genre: this.props.genre, limit: this.props.limit}).then((resp) => { | |
this.setState({meta: resp.body}); | |
}) | |
} | |
render() { | |
return <SongsList metadata={this.state.meta}/>; | |
} | |
} | |
// Presentation (Dumb) | |
const SongsList = (props) => { | |
return ( | |
<div className="metaBox"> | |
{ | |
props.metadata.map((meta) => { | |
return <p key={meta._id}>{meta.album}</p>; | |
}) | |
} | |
</div> | |
) | |
}; | |
export default SongsListContainer; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment