Skip to content

Instantly share code, notes, and snippets.

View christiannaths's full-sized avatar
🍕
Eating pizza

Christian Naths christiannaths

🍕
Eating pizza
View GitHub Profile
@christiannaths
christiannaths / article-feed.md
Last active May 20, 2017 17:49
Article Feed Component

Component Structure

Option: pre-render articles via server-side page load & pass them directly into component via props. You'd still need to wait for the JS bundle to load before users would see the list, but it would cut out an extra round-trip to your server

render(
  <ArticleFeed articles={articlesArrayProvidedFromPageLoad} />,
  document.getElementById('#article-feed-root')
);
/**
* Option: pre-render articles via server-side page load & pass
* them directly into component via props.
*
* render(
* <ArticleFeed articles={articlesArrayProvidedFromPageLoad} />
* );
*
* otherwise use XHR request in <ArticleFeed /> component's
* "componentDidMount" lifecycle function. This function's
@christiannaths
christiannaths / user-settings.js
Last active February 13, 2017 23:57
my-app/src/components/user-settings.js
import React from 'react'
import { connect } from 'react-redux'
import { actions } from '../store/actions'
const mapStateToProps = (state) => ({
notificationsState: state.settings.notifications ? 'on' : 'off'
})
const NotificationsSelect = ({notificationsState}) => (
<div>
@christiannaths
christiannaths / App.js
Last active March 24, 2025 12:30
my-app/src/App.js
import React, { Component } from 'react'
import logo from './logo.svg'
import './App.css'
import NotificationsSwitch from './components/notifications-switch'
import UserSettings from './components/user-settings'
class App extends Component {
render () {
return (
<div className='App'>
@christiannaths
christiannaths / notifications-select.js
Last active February 13, 2017 23:58
my-app/src/components/notifications-select.js
import React from 'react'
import { connect } from 'react-redux'
import { actions } from '../store/actions'
const mapStateToProps = (state) => ({
notifications: state.settings.notifications
})
const NotificationsSelect = ({notifications, dispatch}) => (
<label>
@christiannaths
christiannaths / notifications-switch.js
Last active February 13, 2017 23:59
my-app/src/components/notifications-switch.js
import React from 'react'
import { connect } from 'react-redux'
import { actions } from '../store/actions'
const mapStateToProps = (state) => ({
notifications: state.settings.notifications
})
const NotificationsSwitch = ({notifications, dispatch}) => (
<label>
@christiannaths
christiannaths / actions.js
Last active February 13, 2017 23:59
my-app/src/store/actions.js
export const TYPES = {
SET_NOTIFICATIONS: 'SET_NOTIFICATIONS'
}
export const actions = {
setNotifications: (bool) => ({ type: TYPES.SET_NOTIFICATIONS, bool })
}
@christiannaths
christiannaths / reducers.js
Last active February 13, 2017 23:59
my-app/src/store/reducers.js
import { TYPES } from './actions'
const initialStates = {
settings: {
notifications: true
}
}
export const settings = (state = initialStates.settings, action) => {
switch (action.type) {
@christiannaths
christiannaths / index.js
Last active February 14, 2017 00:00
my-app/src/store/index.js
import { createStore, combineReducers } from 'redux'
import { settings } from './reducers'
const rootReducer = combineReducers({
settings
})
export default createStore(rootReducer)
@christiannaths
christiannaths / index.js
Last active February 14, 2017 00:00
my-app/src/index.js
import React from 'react'
import ReactDOM from 'react-dom'
import App from './App'
import './index.css'
import { Provider } from 'react-redux'
import store from './store'
ReactDOM.render(
<Provider store={store}>
<App />