This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
entry: './js/src/app.js', | |
output: { | |
filename: './js/build/bundle.js' | |
}, | |
module: { | |
loaders: [ | |
{ | |
test: /\.jsx?$/, | |
loader: 'babel', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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 = [{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Child extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
error: false | |
}; | |
this.handleClick = this.handleClick.bind(this); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Info extends Component { | |
constructor(props) { | |
super(props); | |
} | |
render() { | |
return <Modal><Text text=“This is the text” /></Modal>; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Modal extends Component { | |
constructor(props) { | |
super(props); | |
} | |
render() { | |
const node = document.getElementById(‘modal’); | |
return ReactDOM.createPortal(this.props.children, node); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Child.jsx | |
class Child extends React.Component { | |
constructor(props) { | |
super(props); | |
} | |
render() { | |
return ( | |
<button | |
type="button" | |
onClick={ this.props.updateParent } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 => { |