Skip to content

Instantly share code, notes, and snippets.

View andrewtremblay's full-sized avatar
🕵️‍♂️
Working on secret stuff.

Andrew Tremblay andrewtremblay

🕵️‍♂️
Working on secret stuff.
View GitHub Profile
@andrewtremblay
andrewtremblay / use-toggle.ts
Created July 26, 2022 16:47 — forked from fnky/use-toggle.ts
Simple toggle hook using useReducer w/ types for reducer with optional action.
import React from "react";
type ReducerWithOptionalAction<S> = (prevState: S, action?: S) => S;
type ReducerStateWithOptionalAction<S> = React.ReducerState<ReducerWithOptionalAction<S>>;
type DispatchWithOptionalAction<S> = React.Dispatch<S> & React.DispatchWithoutAction;
type ReducerValueWithOptionalAction<S> = [
ReducerStateWithOptionalAction<S>,
React.DispatchWithOptionalAction<S>,
];