Skip to content

Instantly share code, notes, and snippets.

@zaagan
Last active January 15, 2019 07:01
Show Gist options
  • Save zaagan/cf2c9987ec260d0bb479a5be7ef9f7ff to your computer and use it in GitHub Desktop.
Save zaagan/cf2c9987ec260d0bb479a5be7ef9f7ff to your computer and use it in GitHub Desktop.
ReactJS Code snippets #react #routes #gitignore #snippets #reactjs
import React, { Component } from "react";
import PropTypes from "prop-types";
import { withRouter } from "react-router";
import { withStyles } from "@material-ui/core/styles";
import compose from "recompose/compose";
import { connect } from "react-redux";
import Typography from "@material-ui/core/Typography";
const styles = theme => ({});
class MyComp extends Component {
constructor(props) {
super(props);
this.state = {
}
}
render() {
const { classes, note } = this.props;
return (
<div>
<div className="section-preview-row">
<Typography className="section-preview-heading">
{note.content}
</Typography>
</div>
</div>
);
}
}
MyComp.propTypes = { classes: PropTypes.object.isRequired, };
const mapStateToProps = state => ({});
export default compose(
withRouter,
withStyles(styles),
connect(mapStateToProps)
)(MyComp);
// SOURCE: https://stackoverflow.com/a/47859063/3436775
const json = [{
"id" : "001",
"item" : "samsung",
"quantity" : 1,
"price" : 300,
},
{
"id" : "002",
"item" : "iphone",
"quantity" : 2,
"price" : 450,
}];
const total = json.map(({quantity, price}) => quantity * price)
.reduce((a, b) => a + b)
console.log(total)
// OUTPUT : 1200
import React from 'react';
import {Route, IndexRoute} from 'react-router';
import Template from './components/template';
import HomePage from './components/home/HomePage';
import AboutPage from './components/about/AboutPage';
import CoursePage from './components/courses/CoursePage';
export default (
<Route path="/" component={Template}>
<IndexRoute component={HomePage} />
<Route path="about" component={AboutPage} />
<Route path="courses" component={CoursePage} />
</Route>
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment