Skip to content

Instantly share code, notes, and snippets.

View Ricki-BumbleDev's full-sized avatar

Ricki Ricki-BumbleDev

View GitHub Profile
import { DependencyList, EffectCallback, useEffect, useRef } from 'react';
const useDeepEffect = (effect: EffectCallback, deps?: DependencyList) => {
const prevDepsRef = useRef<DependencyList>();
useEffect(() => {
if (JSON.stringify(deps) === JSON.stringify(prevDepsRef.current)) {
return;
}
prevDepsRef.current = deps;
return effect();
const isTruthy = (value: any) => typeof value === 'number' || Boolean(value);
const removeEmpty = (value: any) => {
if (Array.isArray(value)) {
const newValue = value.map(removeEmpty).filter(isTruthy);
if (!newValue.length) {
return undefined;
}
return newValue;
} else if (typeof value === 'object' && value !== null && !(value instanceof Date)) {
@Ricki-BumbleDev
Ricki-BumbleDev / CJA.md
Created December 4, 2019 18:50
CJA - Casual JSON API

CJA - Casual JSON API

This is a specification for building JSON HTTP API endpoints for exchanging data between e.g. clients and servers.

Basic URL structure

/api/<version>/<entity>/<action>/<identifier>

/api subpath and version

Serving the API under a separate /api path is optional, it usually helps to route requests correctly. If this rule is applied it should be consistently used for all endpoints.