Skip to content

Instantly share code, notes, and snippets.

View arackaf's full-sized avatar
🏠
Working from home

Adam Rackis arackaf

🏠
Working from home
View GitHub Profile
plugins: [
(isProduction ?
new BundleAnalyzerPlugin({
analyzerMode: 'static'
}) : null),
new webpack.optimize.CommonsChunkPlugin({
name: 'node-static',
minChunks(module, count) {
var context = module.context;
var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
var path = require('path');
var webpack = require('webpack');
var noVisualization = process.env.NODE_ENV === 'production'
|| process.argv.slice(-1)[0] == '-p'
|| process.argv.some(arg => arg.indexOf('webpack-dev-server') >= 0);
module.exports = {
entry: {
main: './reactStartup.js'
class Counter extends Component {
componentWillMount() {
let self = this;
class IfEven extends Component {
render() {
let {children} = this.props;
return !(self.props.value % 2) ? children : null;
}
}
class CurrentTime extends Component {
state = {time: ''};
componentDidMount() {
this._interval = setInterval(() => this.setState({time: this.getTime()}), 50);
}
componentWillUnmount() {
clearInterval(this._interval);
}
getTime(){
let t = new Date();
class ShowCurrentTime extends Component {
render() {
return (
<div>
<span style={{color: 'blue'}}>Time is {this.props.time}</span>
</div>
);
}
}
import {render} from 'react-dom';
import React, {Component, Children, cloneElement} from 'react';
class CurrentTime extends Component {
state = {time: ''};
componentDidMount() {
this._interval = setInterval(() => this.setState({time: this.getTime()}), 50);
}
componentWillUnmount() {
clearInterval(this._interval);
render(
<div>
<CurrentTime>
<div>
<span>{/* Can't get time here :( */}</span>
</div>
</CurrentTime>
</div>, document.getElementById('home')
);
import {render} from 'react-dom';
import React, {Component, Children, cloneElement} from 'react';
const currentTime = OriginalComponent => class extends Component {
state = {time: ''};
componentDidMount() {
this._interval = setInterval(() => this.setState({time: this.getTime()}), 50);
}
componentWillUnmount() {
clearInterval(this._interval);
class ShowCurrentTimeRaw extends Component {
render() {
return (
<div style={this.props.style}>
<span style={{color: 'purple'}}>Time is {this.props.time}</span>
</div>
);
}
}
const ShowCurrentTime = currentTime(ShowCurrentTimeRaw);
import {render} from 'react-dom';
import React, {Component, Children, cloneElement} from 'react';
class CurrentTime extends Component {
state = {time: ''};
componentDidMount() {
this._interval = setInterval(() => this.setState({time: this.getTime()}), 50);
}
componentWillUnmount() {
clearInterval(this._interval);