Created
August 31, 2018 02:45
-
-
Save jarbacoa/da9790893fc779d4a101d27f3f67b21e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 { getBeatsByTag } from "../../actions/beatActions"; | |
| import { Link } from "react-router-dom"; | |
| import PropTypes from "prop-types"; | |
| class BeatsByTag extends Component { | |
| constructor(props) { | |
| super(props); | |
| this.state = { | |
| beats: [] | |
| }; | |
| } | |
| componentDidMount() { | |
| if (this.props.match.params.tag) { | |
| this.props.getBeatsByTag(this.props.match.params.tag); | |
| } | |
| } | |
| render() { | |
| const { beats } = this.state; | |
| let content; | |
| content = beats.map(b => <Link to="/">{b.name}</Link>); | |
| return <div>{content ? content : null}</div>; | |
| } | |
| } | |
| BeatsByTag.propTypes = { | |
| getBeatsByTag: PropTypes.func.isRequired, | |
| beat: PropTypes.object.isRequired, | |
| error: PropTypes.object.isRequired | |
| }; | |
| const mapStateToProps = state => ({ | |
| beat: state.beat, | |
| error: state.error | |
| }); | |
| export default connect(mapStateToProps, { getBeatsByTag })(BeatsByTag); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment