Skip to content

Instantly share code, notes, and snippets.

@Retsam
Retsam / example.tsx
Last active Dec 3, 2020
Minimal data fetching LoadState
View example.tsx
type LoadState<T> =
| { state: "loading" }
| { state: "loaded", data: T }
// Not all usecases will have an error state, in which case it's fine to omit it here.
| { state: "error", err: string };
type ExamplePayload = string;
const ExampleComponent = () => {
const [ loadState, setLoadState ] = useState<LoadState<ExamplePayload>>({ state: "loading });
useEffect(() => {
@Retsam
Retsam / exampleState.ts
Last active Mar 11, 2020
Redux-like useReducer pattern
View exampleState.ts
import { Dispatch, useReducer, useEffect } from "react";
import { produce } from "immer";
//=======
// State
//=======
export type ExampleState = {
name: string;
level: number;
saved: false;
@Retsam
Retsam / a.js
Created Sep 13, 2017
Webpack CommonsChunkPlugin issue
View a.js
import c from "./c";
export default "a" + c;
@Retsam
Retsam / app.js
Last active Feb 8, 2016
App Versioning Structure
View app.js
import v1 from "./v1"
import v2 from "./v2"
import express from "express";
var app = express();
app.use("/v1", v1);
app.use("/v2", v2);
@Retsam
Retsam / BabelBug.js
Last active Aug 29, 2015
BabelJS Bug
View BabelBug.js
//Expected output: A B C (see http://www.es6fiddle.net/ice1qchm/)
//Actual output from Babel: A C
//ES5 legacy code
function A () {
console.log("A");
}
function B () {
You can’t perform that action at this time.