I recently started to learn React in more depth, and something is triggering me because I cant understand this syntax (I know is a ES6 thing)
So I got this component, lets call it and this component will receive an onClick function as a prop with one param, so we have <Component onClick={() => handleClick("clicked")}/>
This Component, has a callAll function and is implemented like this
const callAll = (...fns) => (...args) => fns.forEach(fn => fn && fn(...args))
const Component = ({children: child}) => {
return React.cloneElement(child, {
onClick: callAll(() => setIsOpen(true), child.props.onClick),
})
}
My question is where does the ...args come from, in the sense of how does the inner function of 'callAll' receive all the args of each specific function magically just by typing '...args'?
I hope I explained myself, thanks!