Last active
July 15, 2020 21:38
-
-
Save skflowne/5e507ef80c627be8657ce37f4b841521 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// j'ai fait une erreur au niveau du debounce | |
const debouncedRender = useRef( | |
debounce((config) => { | |
console.log("render report", config) | |
}, 1000) | |
) | |
const setChildrenEnabled = (section, enabled) => { | |
const children = section.children | |
let newChildren = {} | |
if (children) { | |
newChildren = Object.keys(children).reduce((obj, key) => { | |
const childSection = children[key] | |
obj[key] = setChildrenEnabled(childSection, enabled) | |
return obj | |
}, {}) | |
} | |
return { ...section, enabled, children: newChildren } | |
} | |
const handleChange = (path, enabled) => { | |
let newSection = path ? { ...get(config, path), enabled } : { ...config, enabled } | |
newSection = setChildrenEnabled(newSection, enabled) | |
const newConfig = path ? { ...set(config, path, newSection) } : newSection | |
setConfig(newConfig) | |
debouncedRender.current(newConfig) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment