Skip to content

Instantly share code, notes, and snippets.

@snigo
Last active October 6, 2023 08:52
Show Gist options
  • Save snigo/096303a0904584950d5e250c4243310d to your computer and use it in GitHub Desktop.
Save snigo/096303a0904584950d5e250c4243310d to your computer and use it in GitHub Desktop.
SOLID React article, code snippet 7: Children prop in React
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