Skip to content

Instantly share code, notes, and snippets.

@jarbacoa
Created August 31, 2018 02:45
Show Gist options
  • Select an option

  • Save jarbacoa/da9790893fc779d4a101d27f3f67b21e to your computer and use it in GitHub Desktop.

Select an option

Save jarbacoa/da9790893fc779d4a101d27f3f67b21e to your computer and use it in GitHub Desktop.
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