Skip to content

Instantly share code, notes, and snippets.

View DSchau's full-sized avatar

Dustin Schau DSchau

View GitHub Profile
@DSchau
DSchau / gatsby-ssr.js
Created February 26, 2019 17:14
Prelim. version of Gatsby + Ionic
const { renderToString } = require(`react-dom/server`)
exports.replaceRenderer = function replaceRenderer({ bodyComponent, replaceBodyHTMLString }) {
const bodyHTML = renderToString(bodyComponent)
// parse into document (and inject this into stencil SSR)
// call SSR APIs
// call replaceBodyHTMLString with hydrated HTML
}
@DSchau
DSchau / index.js
Created February 22, 2019 20:18
Gatsby page example
import React from 'react'
export default class IndexPage extends React.Component {
// don't do this 😈
componentDidMount() {
const node = document.getElementById('whatever')
node.style.color = 'blue'
}
render() {
@DSchau
DSchau / prune-length-result.json
Created February 21, 2019 20:21
Prune Length
{
"data": {
"allMarkdownRemark": {
"edges": [
{
"node": {
"excerpt": "gatsby-plugin-page-creator Gatsby plugin that automatically creates pages from React components in specified directories. Gatsby\nincludes…",
"excerptAst": {
"type": "root",
"children": [
@DSchau
DSchau / bio.js
Created January 29, 2019 17:52
An example of a Bio component that can be used wherever
import React from 'react'
import { StaticQuery, graphql } from 'gatsby'
export default function Bio() {
return (
<StaticQuery
query={graphql`
{
file({ relativePath: { regex: "/bio.md/" }}) {
childMarkdownRemark {
@DSchau
DSchau / gatsby-ssr.js
Created January 29, 2019 17:06
An example of Gatsby SSR APIs
const { Helmet } = require('react-helmet')
const { onRenderBody } = require('gatsby/ssr')
onRenderBody(({ setHeadComponents, setHtmlAttributes, setBodyAttributes }) => {
const helmet = Helmet.renderStatic()
setHtmlAttributes(helmet.htmlAttributes.toComponent())
setBodyAttributes(helmet.bodyAttributes.toComponent())
setHeadComponents([
helmet.title.toComponent(),
helmet.link.toComponent(),
@DSchau
DSchau / gatsby-node.js
Created January 29, 2019 17:02
Example with Gatsby Node APIs
const path = require('path')
const { createPages } = require('gatsby/node')
createPages(async ({ actions, graphql }) => {
const { createPage } = actions
const result = await graphql(`
{
allMarkdownRemark {
edges {
@DSchau
DSchau / gatsby-browser.js
Last active January 29, 2019 17:03
Example with Gatsby Browser APIs
import React from 'react'
import { wrapRootElement } from 'gatsby/browser'
wrapRootElement(({ element }) => (
<div>{element}</div>
))
@DSchau
DSchau / index.js
Created January 4, 2019 02:19
React SSR vs. client-side rendering
import React, { Component } from 'react'
import fetch from 'isomorphic-fetch'
import Layout from '../components/layout'
export default class IndexPage extends Component {
state = {
data: []
}
@DSchau
DSchau / gatsby-config.js
Last active December 10, 2018 19:50
Customer setup for Gatsby Preview
module.exports = {
plugins: [
{
resolve: 'gatsby-source-contentful',
options: {
spaceId: process.env.GATSBY_CONTENTFUL_SPACE_ID || process.your.CONTENTFUL_SPACE_ID,
accessToken: process.env.GATSBY_CONTENTFUL_ACCESS_TOKEN || process.env.CONTENTFUL_ACCESS_TOKEN,
host: process.env.GATSBY_CONTENTFUL_HOST || process.env.CONTENTFUL_HOST
}
}
@DSchau
DSchau / shallow-clone.sh
Last active December 3, 2018 20:56
A shell script to clone a folder in a repo
#!/bin/bash
# shallow_clone local_folder example-name
## shallow_clone using-jest-example using-jest
fun shallow_clone () {
folder=$1
example=$2
mkdir $folder
cd $folder