@hyeon/react-use
Advanced tools
Comparing version 0.0.9 to 0.0.10
export * from './packages/useRemoveSpaceProgramming'; | ||
export * from './packages/useDeepMerge'; |
@@ -6,2 +6,3 @@ import { pipe } from 'fp-ts/lib/function'; | ||
import { useState, useCallback } from 'react'; | ||
import { pipe as pipe$1 } from 'fp-ts/function'; | ||
@@ -32,3 +33,27 @@ // 이 hook에서 메인이 되는 함수이다. | ||
export { obj2keyMap, useObj2KeyMap, useRSP, useRemoveSpaceProgramming }; | ||
const isObject = obj => obj !== null && typeof obj === 'object'; | ||
const deepMerge = source => target => { | ||
let output = Object.assign({}, source); | ||
if (isObject(source) && isObject(target)) { | ||
if (Array.isArray(source) && Array.isArray(target)) { | ||
output = [...source, ...target]; | ||
} else { | ||
Object.keys(target).forEach(key => { | ||
if (isObject(source[key]) && isObject(target[key])) { | ||
output[key] = deepMerge(source[key])(target[key]); | ||
} else { | ||
output[key] = target[key]; | ||
} | ||
}); | ||
} | ||
} | ||
return output; | ||
}; | ||
const useDeepMerge = (obj, merge) => { | ||
const [value, setValue] = useState(pipe$1(obj, deepMerge(merge))); | ||
const setDeppMerge = useCallback(tree => setValue(tree), [setValue]); | ||
return [value, setDeppMerge]; | ||
}; | ||
export { deepMerge, obj2keyMap, useDeepMerge, useObj2KeyMap, useRSP, useRemoveSpaceProgramming }; | ||
//# sourceMappingURL=index.esm.js.map |
{ | ||
"name": "@hyeon/react-use", | ||
"version": "0.0.9", | ||
"version": "0.0.10", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "files": [ |
Sorry, the diff of this file is not supported yet
12849
15
90