Skip to content

Instantly share code, notes, and snippets.

@noizbuster
Created July 31, 2021 17:09
Show Gist options
  • Save noizbuster/29d44ec6b61319465e138a10a619ab05 to your computer and use it in GitHub Desktop.
Save noizbuster/29d44ec6b61319465e138a10a619ab05 to your computer and use it in GitHub Desktop.
utilities for hookstate
import _ from 'lodash';
export function cloneState(stateValue, path) {
const value = path ? _.get(stateValue, path) : stateValue;
if (!value) {
return value;
}
return JSON.parse(JSON.stringify(value));
}
export function partialUpdate(key, value) {
return (p) => ({ ...p, [key]: value });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment