I came across some code in review and had a question on best practices. Here's the scenario:
I've got a Hyperlink
component with a url
prop. If for some reason url
is falsy, Hyperlink
renders null
.
simplified example:
const Hyperlink = ({ url }) => {
return !url ? null : <SomethingElse url={url} />;
};
Does this logic belong in the Hyperlink
component, or should it be the responsibility of the parent component to determine whether or not to render something?
example:
const MyParentComponent = ({ url }) => {
return !url ? null : <Hyperlink url={url} />
};
This keeps Hyperlink
dumb, with the downside of having to sprinkle that logic in places url
is optional.