prismicio / prismic-react

React components and hooks to fetch and present Prismic content
https://prismic.io/docs/technologies/homepage-reactjs
Apache License 2.0
154 stars 40 forks source link

Add `fallback` prop to PrismicRichText #129

Closed angeloashmore closed 2 years ago

angeloashmore commented 2 years ago

Is your feature request related to a problem? Please describe.

Adding a fallback prop to <PrismicRichText> would be helpful to render content when a field's value is empty.

This functionality should mirror <PrismicText>'s fallback prop. See #105 for more details.

Describe the solution you'd like

<PrismicRichText
  field={document.data.richTextField}
  fallback={<p>Empty content</p>}
/>

Describe alternatives you've considered

To do this today, one must use isFilled.richText() from @prismicio/helpers in a ternary.

<div>
  {prismicH.isFilled.richText(document.data.richTextField) ? (
    <PrismicRichText field={document.data.richTextField} />
  ) : (
    <p>Empty content</p>
  )}
</div>

This is verbose and requires using a separate library.

Additional context

N/A

angeloashmore commented 2 years ago

Completed in #135.