Skip to content

Instantly share code, notes, and snippets.

View smidhonza's full-sized avatar
🏡
wfh

Honza Smid smidhonza

🏡
wfh
View GitHub Profile
const has = <T extends object>(property: keyof T) => (obj: T) => !!obj[property];
const head: <T>(array: T[]) => T | undefined = (array) => array[0];
const prop = <T>(property: keyof T) => (object: T) => object[property];
const path = (bits: string[]) => (object: any): any => {
const [property, ...rest] = bits;
const value = prop(property)(object);
if (head(rest)) {
return path(rest)(value);
}
return value;
import React from 'react';
const Demo = () => {
const [value, setValue] = React.useState();
const [data, setData] = React.useState();
React.useEffect(() => {
const fetchData = async () => {
if (value) { // dont call the fetch on initial load when value is empty
const result = await fetch('https://.....');

Keybase proof

I hereby claim:

  • I am smidhonza on github.
  • I am smidhonza (https://keybase.io/smidhonza) on keybase.
  • I have a public key whose fingerprint is EDFE 09AF A5C7 49E7 DD61 4E1C CF19 A0D6 6147 4AE9

To claim this, I am signing this object:

@smidhonza
smidhonza / curry.js
Created June 12, 2017 21:32
ES6 Curry
export const curry = (fn) => {
const r = (args) => {
if (args.length >= fn.length) {
return fn(...args);
}
return (...secArgs) => r([...args, ...secArgs]);
};
return (...args) => r(args);
};