Skip to content

Instantly share code, notes, and snippets.

View pkellner's full-sized avatar

Peter Kellner pkellner

View GitHub Profile
@pkellner
pkellner / ErrorSegment.tsx
Created December 21, 2018 18:25
Be nice to get some hint of what type children should be in typescript
import React, {FunctionComponent} from 'react';
interface Props {
errorMessage: string,
children: JSX.Element
}
const ErrorSegment: FunctionComponent<Props> =
({errorMessage,children}) => {
return (
@pkellner
pkellner / next.config.js
Created November 11, 2018 21:43
Sample next.config.js for Next.js that includes environment variables, and other plugins (CSS and Image)
const withCSS = require("@zeit/next-css");
require('dotenv').config()
const path = require('path')
const Dotenv = require('dotenv-webpack')
const withImages = require('next-images')
module.exports = withCSS(withImages({
inlineImageLimit: 16384,
webpack(config, options) {
<Link
href={{
pathname: "/session", query:
{
sessionSlug: 'cracking-the-product-manager-interview',
sessionId: '7368',
sessionData: {
id: 7368,
junk: 'abcd',
sessionSlug: 'cracking-the-product-manager-interview'}
@pkellner
pkellner / index.js
Created October 30, 2018 18:14
This is a revised version of the data-fetch example index.js file from https://github.com/zeit/next.js/blob/canary/examples/data-fetch/pages/index.js
import React from 'react'
import Link from 'next/link'
import axios from 'axios'
export default class Index extends React.Component {
constructor(props) {
super(props);
console.log("Index:constructor called");
this.state = {
@pkellner
pkellner / server.js
Created October 2, 2018 16:46
When using next-router with nextjs and you set useFileSystemPublicRoutes: false, you need a server.js like this to find your home route. See https://spectrum.chat/?t=eeaebd2e-e337-401c-9e29-d7558202e76b
const { createServer } = require("http");
const next = require("next");
const routes = require("./routes");
const { parse } = require("url");
const port = parseInt(process.env.PORT, 10) || 3000;
const dev = process.env.NODE_ENV !== "production";
const app = next({ dev });
const handler = routes.getRequestHandler(app);
@pkellner
pkellner / Speakers.js
Created July 26, 2018 02:09
Componet/Speakers.js
import React, {Component} from 'react';
import SpeakersHeader from './SpeakersHeader';
import SpeakerList from './SpeakerList';
import axios from "axios";
class Speakers extends Component {
constructor(props) {
super(props);
this.state = {
@pkellner
pkellner / speaker.js
Created July 26, 2018 02:08
/pages/speaker.js
import React, {Component} from 'react';
import Layout from "../src/components/codecamp/common/Layout";
import Speakers from "../src/components/codecamp/speakers/Speakers";
import axios from "axios";
class speakers extends Component {
constructor(props) {
super();
@pkellner
pkellner / FullPage.js
Created May 26, 2018 16:23
FullPage.js - 3rd Module - Custom WebPack
import React, { Component } from 'react';
import CodeCampMenu from './CodeCampMenu';
import PageTop from './PageTop';
import Footer from './Footer';
import Routes from '../../Routes';
class FullPage extends Component {
@pkellner
pkellner / Component.js
Created January 16, 2018 22:57
React Component To Show Loading a Waiting Message Only When Necessary
import React, {Component} from 'react';
import axios from 'axios';
class App extends Component {
constructor() {
super();
this.timeIncrementMs = 50;
this.showSpinnerIfReturnGreaterThanMs = 200;
this.state = {
import express from 'express';
import renderer from './renderer';
const app = express();
app.use(express.static('public', {
// index: false
index: false
}));