Skip to content

Instantly share code, notes, and snippets.

View jaredpalmer's full-sized avatar

Jared Palmer jaredpalmer

View GitHub Profile
@jaredpalmer
jaredpalmer / SharedChangeHandler.js
Last active June 16, 2017 00:09
SharedChangeHandler.js
import React, { Component } from 'react';
class Reservation extends Component {
state = {
isGoing: true,
numberOfGuests: 2
};
handleInputChange = (event) => {
const target = event.target;
@jaredpalmer
jaredpalmer / App.js
Created May 30, 2017 17:45
Next.js-like SSR without Next.js.
import React from 'react';
import Route from 'react-router-dom/Route';
import Link from 'react-router-dom/Link';
import Switch from 'react-router-dom/Switch';
const App = ({ routes, initialData }) => {
return routes
? <div>
<Switch>
{routes.map((route, index) => {
@jaredpalmer
jaredpalmer / Dao.ts
Created May 28, 2017 20:05
Dao Hapi.js Example
import * as Joi from 'joi';
import * as monk from 'monk';
export interface DaoProps {
/**
* Name of table
*/
name: string;
/**
@jaredpalmer
jaredpalmer / razzle.config.js
Last active April 30, 2019 17:19
Razzle with HappyPack, TypeScript, SCSS, and Vendor bundle
'use strict';
const autoprefixer = require('autoprefixer');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const path = require('path');
const {
CheckerPlugin,
TsConfigPathsPlugin,
} = require('awesome-typescript-loader');
const HappyPack = require('happypack');
@jaredpalmer
jaredpalmer / debug.js
Created May 11, 2017 21:15
Debug Helper
import React from 'react';
import toClass from 'recompose/toClass';
export default function debug(WrappedComponent) {
if (typeof WrappedComponent === 'function') {
WrappedComponent = toClass(WrappedComponent);
}
return class Enhancer extends WrappedComponent {
@jaredpalmer
jaredpalmer / react-popover.js
Created April 13, 2017 20:27
React Popover Example
import React from 'react';
class PopoverExample extends React.Component {
state = {
isOpen: false,
};
toggle = () => {
this.setState(state => ({
isOpen: !state.isOpen,
@jaredpalmer
jaredpalmer / withSSR.js
Last active August 1, 2019 00:40
SSR HOC
import React from 'react';
import axios from 'axios';
// This is a Higher Order Component that abstracts duplicated data fetching
// on the server and client.
export default function SSR(Page) {
class SSR extends React.Component {
static getInitialData(ctx) {
// Need to call the wrapped components getInitialData if it exists
return Page.getInitialData
@jaredpalmer
jaredpalmer / ZoomToMeters.js
Created March 16, 2017 23:11
Google Maps Zoom Levels to Meters
module.exports = {
'20': '1128.497220',
'19': '2256.994440',
'18': '4513.988880',
'17': '9027.977761',
'16': '18055.955520',
'15': '36111.911040',
'14': '72223.822090',
'13': '144447.644200',
'12': '288895.288400',
@jaredpalmer
jaredpalmer / InfiniteScroll.js
Created March 2, 2017 20:19 — forked from lelandrichardson/InfiniteScroll.js
Super Light Infinite Scroll Component in React
var React = require('react');
var { Component, PropTypes } = React;
var throttle = require('lodash/function/throttle');
class InfiniteScroll extends React.Component {
static propTypes = {
hasMore: PropTypes.bool.isRequired,
isLoading: PropTypes.bool.isRequired,
onLoadMore: PropTypes.func.isRequired,
threshold: PropTypes.number,
@jaredpalmer
jaredpalmer / editabletext.js
Created February 26, 2017 01:30
editabletext.js
/**
* This is converted from @palantir/blueprint's editable text.
*
* @see http://blueprintjs.com/docs/#components.editable
*/
import React, {Component} from 'react'
import classNames from 'classnames'
import { clamp, safeInvoke } from '../utils'
import PureRender from "pure-render-decorator";