Skip to content

Instantly share code, notes, and snippets.

@skflowne
Last active July 15, 2020 21:38
Show Gist options
  • Save skflowne/5e507ef80c627be8657ce37f4b841521 to your computer and use it in GitHub Desktop.
Save skflowne/5e507ef80c627be8657ce37f4b841521 to your computer and use it in GitHub Desktop.
// 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