Skip to content

Instantly share code, notes, and snippets.

View ekaone's full-sized avatar
🎯
Focusing

Eka Prasetia ekaone

🎯
Focusing
View GitHub Profile
@ekaone
ekaone / memoizedHandlers.js
Created February 2, 2021 06:28 — forked from kyleshevlin/memoizedHandlers.js
Using React.useMemo to create a `handlers` object
// One of my new favorite React Hook patternms is to create handler
// functions for a custom hook using `React.useMemo` instead of
// `React.useCallback`, like so:
function useBool(initialState = false) {
const [state, setState] = React.useState(initialState)
// Instead of individual React.useCallbacks gathered into an object
// Let's memoize the whole object. Then, we can destructure the
// methods we need in our consuming component.
@ekaone
ekaone / node_redis_cache.js
Created August 21, 2019 07:53 — forked from bradtraversy/node_redis_cache.js
Node.js & Redis Caching
const express = require('express');
const fetch = require('node-fetch');
const redis = require('redis');
const PORT = process.env.PORT || 5000;
const REDIS_PORT = process.env.PORT || 6379;
const client = redis.createClient(REDIS_PORT);
const app = express();