Why does this work:
interface UserSidebarProps {
children? : React.ReactNode
}
function UserSidebar({children}: UserSidebarProps) {
return (
<div>
{children}
</div>
)
}
But this does not
function UserSidebar(children?: React.ReactNode) {
return (
<div>
{children}
</div>
)
}
// Usage
<UserSidebar>hello world</UserSidebar>
When trying to use it, the second option gives an error in vscode of:
Type '{ children: Element | null; }' is not assignable to type 'IntrinsicAttributes & ReactNode'.
Type '{ children: Element | null; }' is missing the following properties from type 'ReactPortal': key, type, props
I would have thought these two definitions are completely equivalent, how are they different and what am I doing wrong?
UserSidebar({children})vsUserSidebar(children). Fix that first, then try again.