Skip to content

Instantly share code, notes, and snippets.

View ArunMichaelDsouza's full-sized avatar

Arun Michael Dsouza ArunMichaelDsouza

View GitHub Profile
@ArunMichaelDsouza
ArunMichaelDsouza / webpack.config.js
Created October 18, 2016 23:38 — forked from learncodeacademy/webpack.config.js
Sample Basic Webpack Config
var debug = process.env.NODE_ENV !== "production";
var webpack = require('webpack');
module.exports = {
context: __dirname,
devtool: debug ? "inline-sourcemap" : null,
entry: "./js/scripts.js",
output: {
path: __dirname + "/js",
filename: "scripts.min.js"
@ArunMichaelDsouza
ArunMichaelDsouza / redux-form-tut.js
Created October 24, 2016 17:27 — forked from dmeents/redux-form-tut.js
The source code for the redux form tutorial on davidmeents.com
import React, { Component } from 'react';
import { Field, reduxForm } from 'redux-form';
import { connect } from 'react-redux';
import * as actions from '../../actions';
const form = reduxForm({
form: 'ReduxFormTutorial',
validate
});
@ArunMichaelDsouza
ArunMichaelDsouza / webpack.config.js
Created October 27, 2016 16:51
ES6 + JSX Webpack module bundling build script
module.exports = {
entry: './js/src/app.js',
output: {
filename: './js/build/bundle.js'
},
module: {
loaders: [
{
test: /\.jsx?$/,
loader: 'babel',
@ArunMichaelDsouza
ArunMichaelDsouza / webpack.config.js
Last active August 1, 2017 16:52
Demo webpack config for a production build
/* Demo webpack config for a production build
This setup can be further combined with tree-shaking and async code splitting for best results */
const path = require('path'),
webpack = require('webpack'),
buildPath = '../public/assets/js/builds/',
ExtractTextPlugin = require('extract-text-webpack-plugin');
module.exports = [{
@ArunMichaelDsouza
ArunMichaelDsouza / amd-medium-error-boundaries.jsx
Created November 9, 2017 19:28
React 16 error boundaries demo
class Child extends Component {
constructor(props) {
super(props);
this.state = {
error: false
};
this.handleClick = this.handleClick.bind(this);
}
@ArunMichaelDsouza
ArunMichaelDsouza / amd-medium-portals.jsx
Created November 11, 2017 13:28
React 16 portals demo
class Info extends Component {
constructor(props) {
super(props);
}
render() {
return <Modal><Text text=“This is the text” /></Modal>;
}
}
@ArunMichaelDsouza
ArunMichaelDsouza / amd-medium-portals-event-bubbling.jsx
Last active November 11, 2017 14:02
React 16 portals event bubbling demo
class Modal extends Component {
constructor(props) {
super(props);
}
render() {
const node = document.getElementById(‘modal’);
return ReactDOM.createPortal(this.props.children, node);
}
}
@ArunMichaelDsouza
ArunMichaelDsouza / amd-medium-parent-state-update.jsx
Last active December 22, 2017 18:55
Updating state of a parentless component in React
// Child.jsx
class Child extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<button
type="button"
onClick={ this.props.updateParent }
@ArunMichaelDsouza
ArunMichaelDsouza / amd-medium-parent-state-update-2.jsx
Last active December 27, 2017 18:47
Updating state of a parentless component in React
// DeeplyNestedChild.jsx
class DeeplyNestedChild extends React.Component {
constructor(props) {
super(props);
}
updateTopMostParent() {
// Call this method with the state value to update
window.updateTopMostParent(someValue);
}
render() {
@ArunMichaelDsouza
ArunMichaelDsouza / app.js
Created December 31, 2017 13:23 — forked from acdlite/app.js
Quick and dirty code splitting with React Router v4
// getComponent is a function that returns a promise for a component
// It will not be called until the first mount
function asyncComponent(getComponent) {
return class AsyncComponent extends React.Component {
static Component = null;
state = { Component: AsyncComponent.Component };
componentWillMount() {
if (!this.state.Component) {
getComponent().then(Component => {