Simple question: I have read a couple of answers such as this on the differences between Object.assign and the assignment operator (i.e. =) and understand all the points brought up such as that the first copies the object while the latter simply assigns the address.
I want to make a decision on which one to use and would like to know what the implications are for React components as I have seen it being done both ways. Is one an antipattern, in the context of React components, which I should not be considering?
An example of my use-case is as shown below:
function PageSection({children}) {
return <div>{children}</div>
}
function Header({children}) {
return <div>{children}</div>
}
function Body({children}) {
return <div>{children}</div>
}
// Attach components to the `PageSection` component.
export default Object.assign(PageSection, {
Header,
Body,
});
And a related question is, is it an acceptable practice to assign to a property of a property i.e.
Header.CloseButton = CloseButton
PageSection.Header = Header
There are no functional differences besides readability and very slight performance hit by the creation of temporary objects / iterating the enumerable properties (performance difference surely would be negligible to the point where it'd be hard to even measure accurately).
Is equivalent to
I prefer the first example, because it is much clearer what the intent is.