Last active
October 6, 2023 08:52
-
-
Save snigo/096303a0904584950d5e250c4243310d to your computer and use it in GitHub Desktop.
SOLID React article, code snippet 7: Children prop in React
This file contains 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
interface AProps extends React.PropsWithChildren {} | |
interface BProps { | |
childNodes?: React.ReactNode | undefined; | |
} | |
export const A = ({ children }: AProps) => { | |
return <section>{children}</section>; | |
}; | |
export const B = ({ childNodes }: BProps) => { | |
return <section>{childNodes}</section>; | |
}; | |
export const Sections = () => { | |
return ( | |
<> | |
{/** When you write this: */} | |
<A>Children as a nested text node</A> | |
{/** What actually happens behind the scenes is this: */} | |
<A children="Children as a prop instead" /> | |
{/** And if you want you can even rename the prop: */} | |
<B childNodes="Let's rename the prop" /> | |
</> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment