@prismicio/react 2.4.0 → 2.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,9 @@ import * as React from "react";
2
2
  import * as prismicT from "@prismicio/types";
3
3
  import * as prismicH from "@prismicio/helpers";
4
4
 
5
+ import { __PRODUCTION__ } from "./lib/__PRODUCTION__";
6
+ import { devMsg } from "./lib/devMsg";
7
+
5
8
  /**
6
9
  * Props for `<PrismicText>`.
7
10
  */
@@ -42,6 +45,16 @@ export type PrismicTextProps = {
42
45
  * @see Learn about Rich Text fields {@link https://prismic.io/docs/core-concepts/rich-text-title}
43
46
  */
44
47
  export const PrismicText = (props: PrismicTextProps): JSX.Element | null => {
48
+ if (!__PRODUCTION__) {
49
+ if (typeof props.field === "string") {
50
+ throw new Error(
51
+ `[PrismicText] The "field" prop only accepts a Rich Text or Title field's value but was provided a different type of field instead (e.g. a Key Text or Select field). You can resolve this error by rendering the field value inline without <PrismicText>. For more details, see ${devMsg(
52
+ "prismictext-works-only-with-rich-text-and-title-fields",
53
+ )}`,
54
+ );
55
+ }
56
+ }
57
+
45
58
  return React.useMemo(() => {
46
59
  if (prismicH.isFilled.richText(props.field)) {
47
60
  const text = prismicH.asText(props.field, props.separator);