Skip to content

Instantly share code, notes, and snippets.

View misterjohannesson's full-sized avatar
👋

Martin Johannesson misterjohannesson

👋
View GitHub Profile

Keybase proof

I hereby claim:

  • I am objective-mj on github.
  • I am objective (https://keybase.io/objective) on keybase.
  • I have a public key whose fingerprint is 5902 1C10 D32C EF27 5B74 9D0B D900 0618 9FE9 7845

To claim this, I am signing this object:

@misterjohannesson
misterjohannesson / ListReducer.ts
Last active February 11, 2020 09:22
Generic List Reducer, React, Typescript
import { Reducer } from "react";
/**
* Different mutating types to be performed in the reducers dispatch.
*/
export enum ListReducerActionType {
/** Remove one or many item(s) from state */
Remove,
/** Replace one or many item(s) from state if present */
Update,
@misterjohannesson
misterjohannesson / pages_example_[id].ts
Created July 16, 2020 07:56
NextJS API Pages server-side wrapper
import post from "pages/api/post";
import serverApiHandler from "utils/serverApiHandler";
const IdExample = () => <div></div>
IdExample.getInitialProps = async ctx => {
const { query } = ctx;
let id = query.id;
let data = null;
@misterjohannesson
misterjohannesson / useCountdown.ts
Last active December 3, 2020 11:15
useCountdown React Hook
import { parseExpression } from "cron-parser";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
const formatter = Intl.NumberFormat("en-US", {
minimumIntegerDigits: 2,
maximumFractionDigits: 0
});
type Hook<U> = (...x: any[]) => U;
type Return = {