ama icon indicating copy to clipboard operation
ama copied to clipboard

Which is the better pattern for conditional rendering of components that might not have the required props?

Open jroebu14 opened this issue 6 years ago • 0 comments

I'm keen to know if it's better to have conditional render logic inside of the component itself or in the parent component.

const Text = ({ content }) => {
  if (!content) {
    return null;
  }
  return <p>{content}</p>;
};

// then used like
{<Text content={content} />}

versus

const Text = ({ content }) => <p>{content}</p>;

// then used like
{content && <Text content={content} />}

jroebu14 avatar Sep 20 '19 10:09 jroebu14