Skip to content

Instantly share code, notes, and snippets.

View tannerlinsley's full-sized avatar

Tanner Linsley tannerlinsley

View GitHub Profile
@tannerlinsley
tannerlinsley / .eslintrc.js
Created May 15, 2017 19:34
prettier-eslint weirdness
module.exports = {
parserOptions: {
ecmaVersion: 8,
ecmaFeatures: {
experimentalObjectRestSpread: true,
jsx: true,
node: false
},
sourceType: 'module'
},
@tannerlinsley
tannerlinsley / .block
Created April 4, 2018 21:49 — forked from mbostock/.block
Grouped Bar Chart
license: gpl-3.0
// Source
const MyCompSource = ''
// @source MyCompSource
const MyComp = (
<div>
Hello there!
</div>
)
webpack: (config, { stage, defaultLoaders }) => {
/*
* TypeScript Support
* */
// Add .ts and .tsx extension to resolver
config.resolve.extensions.push('.ts', '.tsx')
// Add TypeScript Path Mappings (from tsconfig via webpack.config.js)
// to react-statics alias resolution
@tannerlinsley
tannerlinsley / staticgen-archive.json
Created December 21, 2018 18:33
STATICGEN.COM DATA ARCHIVE
{"timestamp":1545417093036,"data":{"ace":[{"timestamp":1545417093036,"stars":36,"forks":6,"issues":0}],"acrylamid":[{"timestamp":1545417093036,"stars":291,"forks":41,"issues":44}],"adm-dev-kit":[{"timestamp":1545417093036,"stars":29,"forks":4,"issues":11}],"amsf":[{"timestamp":1545417093036,"stars":178,"forks":90,"issues":3}],"anodize":[{"timestamp":1545417093036,"stars":3,"forks":0,"issues":0}],"antwar":[{"timestamp":1545417093036,"stars":431,"forks":32,"issues":8}],"asimov-static":[{"timestamp":1545417093036,"stars":4,"forks":4,"issues":0}],"assemble":[{"timestamp":1545417093036,"stars":3623,"forks":250,"issues":28}],"awestruct":[{"timestamp":1545417093036,"stars":260,"forks":75,"issues":56}],"bake":[{"timestamp":1545417093036,"stars":22,"forks":3,"issues":0}],"bakeit":[{"timestamp":1545417093036,"stars":1,"forks":0,"issues":0}],"baker":[{"timestamp":1545417093036,"stars":40,"forks":7,"issues":1}],"bang":[{"timestamp":1545417093036,"stars":8,"forks":1,"issues":0}],"bashblog":[{"timestamp":1545417093036,"sta

Incremental Builds Experimental API

To use incremental builds (under a hidden flag), use the incremental flag when exporting:

react-static export --incremental`

Then, detect the incremental build in your config and only return the routes you woud like to add, update, or remove.

Incremental builds allow you to:

@tannerlinsley
tannerlinsley / Counter.js
Last active July 8, 2024 07:06
Global React State with Context and Immer
import { useCount, useIncrement, useDecrement } from './store.Count'
export default function Counter () {
const count = useCount()
const increment = useIncrement()
const decrement = useDecrement()
return (
<div>
<div>Count: {count}</div>
@tannerlinsley
tannerlinsley / hooks.js
Created January 25, 2019 17:00
useCancellable, useRefresh combo
const useCancellable = fn => {
const requestRef = useRef(0)
return async (...args) => {
// Keep track of latest promise ID
const id = Date.now()
requestRef.current = id
// Wait for resolution
const res = await fn(...args)
function makeStore() {
// Make a context for the store
const context = React.createContext();
// Make a provider that takes an initialValue
const Provider = ({ initialValue = {}, children }) => {
// Make a new state instance (could even use immer here!)
const [state, setState] = useState(initialValue);
// Memoize the context value to update when the state does
import { StoreProvider, useStore } from './store'
const Counter = () => {
// Use the store
const [state, setState] = useStore();
const increment = () =>
setState(old => ({
...old,
count: old.count + 1