Skip to content

Instantly share code, notes, and snippets.

View davidnguyen11's full-sized avatar
๐Ÿ‘‹

David Nguyen davidnguyen11

๐Ÿ‘‹
View GitHub Profile
@davidnguyen11
davidnguyen11 / README.md
Created February 25, 2017 17:49 — forked from rgrove/README.md
Cake's approach to React Router server rendering w/code splitting and Redux

Can't share the complete code because the app's closed source and still in stealth mode, but here's how I'm using React Router and Redux in a large app with server rendering and code splitting on routes.

Server

  1. Wildcard Express route configures a Redux store for each request and makes an addReducers() callback available to the getComponents() method of each React Router route. Each route is responsible for adding any Redux reducers it needs when it's loaded. (This isn't really necessary on the
@davidnguyen11
davidnguyen11 / ExamplePage.js
Created June 11, 2017 13:55
next.js component with next-redux-wrapper
import React from 'react'
import withRedux from 'next-redux-wrapper'
import { initStore } from '@/store'
class ExamplePage extends React.Component {
render() {
<h1>Hello Next.js</h1>
}
}
@davidnguyen11
davidnguyen11 / CSSTag.js
Last active June 11, 2017 14:43
CSS Tag component serve at development env in next.js
import React from 'react'
const dev = process.env.NODE_ENV !== 'production'
// Note
// this component will only work for ENV = development
function CSSTag (props) {
const { style } = props
const element = dev && <style dangerouslySetInnerHTML={{ __html: style }} />
return element
.indexPage {
.cardItem {
margin-bottom: 15px;
}
}
import React from 'react'
import withRedux from 'next-redux-wrapper'
import { initStore } from '@/store'
// style
import style from '@/styles/index.scss'
class IndexPage extends React.Component {
render() {
<div>
import React from 'react'
import CSSTag from '@/components/CSSTag';
// style
import style from '@/styles/Example.scss'
class Example extends React.Component {
render () {
return (
const gulp = require('gulp')
const sass = require('gulp-sass')
const minifyCSS = require('gulp-csso')
gulp.task('app', () => {
return gulp.src('./styles/**/app.scss')
.pipe(sass().on('error', sass.logError))
.pipe(minifyCSS())
.pipe(gulp.dest('./static/css'))
})
// Future versions of Hyper may add additional config options,
// which will not automatically be merged into this file.
// See https://hyper.is#cfg for all currently supported options.
module.exports = {
config: {
// default font size in pixels for all tabs
fontSize: 12,
// font family with optional fallbacks
import React from 'react'
import ReactDOM from 'react-dom/server'
export default function Noscript (props) {
const staticMarkup = ReactDOM.renderToStaticMarkup(props.children)
return <noscript dangerouslySetInnerHTML={{ __html: staticMarkup }} />
}
@davidnguyen11
davidnguyen11 / introrx.md
Created September 21, 2017 05:24 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing