Skip to content

Instantly share code, notes, and snippets.

View tikotzky's full-sized avatar

Mordy Tikotzky tikotzky

  • QualityBath.com
View GitHub Profile
import { useState, useEffect } from 'react';
// Usage
function App() {
// Call our hook for each key that we'd like to monitor
const happyPress = useKeyPress('h');
const sadPress = useKeyPress('s');
const robotPress = useKeyPress('r');
const foxPress = useKeyPress('f');
function fetchJSON(options, cb) {
const wrappedCb = (...args) => setTimeout(() => cb(...args), 0);
fetch(options).
then(res => res.json()).
then(json => wrappedCb(null, json), err => wrappedCb(err))
}