Skip to content

Instantly share code, notes, and snippets.

@Om4ar
Created March 6, 2018 15:40
Show Gist options
  • Save Om4ar/047b83d775a6a25bd55d34e79c28d8a4 to your computer and use it in GitHub Desktop.
Save Om4ar/047b83d775a6a25bd55d34e79c28d8a4 to your computer and use it in GitHub Desktop.
example of function component with full settings
import React from "react";
import PropTypes from "prop-types";
import Chip from "material-ui/Chip";
import { withStyles } from "material-ui/styles";
const styles = theme => ({
root: {
display: "flex",
flexWrap: "wrap"
},
chip: {
margin: ".2em"
}
});
const TagsFormatter = props => {
const { classes } = props;
const renderTags = props.value.map(t => (
<Chip key={t} label={t} className={classes.chip} />
));
return (
<div className={classes.root}>
{renderTags.length > 0 && renderTags}
{renderTags.length === 0 && <span>-----</span>}
</div>
);
};
TagsFormatter.propTypes = {
value: PropTypes.array.isRequired,
classes: PropTypes.object.isRequired
};
export default withStyles(styles)(TagsFormatter);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment