Skip to content

Instantly share code, notes, and snippets.

@dceddia
dceddia / karma.conf.js
Created Dec 30, 2015
Basic Angular Karma config file
View karma.conf.js
// Karma configuration
// Generated on Tue Dec 29 2015 21:08:31 GMT-0500 (EST)
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
@dceddia
dceddia / config-overrides.dev.js
Created Dec 6, 2016
Customize Create React App without ejecting
View config-overrides.dev.js
module.exports = function(config) {
// Generate sourcemaps
config.devtool = 'source-map';
// Compile i18n messages throughout the project into JSON files
config.module.loaders[0].query.plugins = [
["react-intl", {
"messagesDir": "./build/messages/"
}]
];
View users.js
var express = require('express');
var router = express.Router();
/* GET users listing. */
router.get('/', function(req, res, next) {
// Comment out this line:
//res.send('respond with a resource');
// And insert something like this instead:
res.json([{
View package.json
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"proxy": "http://localhost:3001"
View App.js
import React, { Component } from 'react';
import './App.css';
class App extends Component {
state = {users: []}
componentDidMount() {
fetch('/users')
.then(res => res.json())
.then(users => this.setState({ users }));
@dceddia
dceddia / App.js
Created Oct 20, 2017
Fetching users from Express, while also using React Router
View App.js
import React, { Component } from 'react';
import {
BrowserRouter as Router,
Route,
Link
} from 'react-router-dom';
import './App.css';
class UsersView extends Component {
state = {users: []}
View Counter.js
import React from 'react';
class Counter extends React.Component {
state = { count: 0 }
increment = () => {
this.setState({
count: this.state.count + 1
});
}
View index.js
import React from 'react';
import { render } from 'react-dom';
import Counter from './Counter';
const App = () => (
<div>
<Counter />
</div>
);
@dceddia
dceddia / Counter.js
Created Nov 17, 2017
With state removed
View Counter.js
import React from 'react';
class Counter extends React.Component {
increment = () => {
// fill in later
}
decrement = () => {
// fill in later
}
View index.js
function reducer(state = initialState, action) {
switch(action.type) {
case 'INCREMENT':
return {
count: state.count + 1
};
case 'DECREMENT':
return {
count: state.count - 1
};
You can’t perform that action at this time.