@dotcms/react 0.0.1-beta.9 → 1.0.0-next.2

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.
Files changed (57) hide show
  1. package/README.md +531 -93
  2. package/index.esm.js +2992 -786
  3. package/package.json +10 -12
  4. package/src/index.d.ts +7 -1
  5. package/src/lib/next/__test__/mock.d.ts +2 -1
  6. package/src/lib/next/components/Column/Column.d.ts +1 -1
  7. package/src/lib/next/components/Container/Container.d.ts +1 -1
  8. package/src/lib/next/components/Container/{ContainerFallbakcs.d.ts → ContainerFallbacks.d.ts} +2 -2
  9. package/src/lib/next/components/Contentlet/Contentlet.d.ts +2 -2
  10. package/src/lib/next/components/DotCMSBlockEditorRenderer/DotCMSBlockEditorRenderer.d.ts +27 -0
  11. package/src/lib/{deprecated/components/BlockEditorRenderer/item → next/components/DotCMSBlockEditorRenderer/components}/BlockEditorBlock.d.ts +8 -5
  12. package/src/lib/next/components/DotCMSBlockEditorRenderer/components/blocks/Code.d.ts +24 -0
  13. package/src/lib/next/components/DotCMSBlockEditorRenderer/components/blocks/DotContent.d.ts +14 -0
  14. package/src/lib/next/components/DotCMSBlockEditorRenderer/components/blocks/Image.d.ts +10 -0
  15. package/src/lib/{deprecated/components/BlockEditorRenderer → next/components/DotCMSBlockEditorRenderer/components}/blocks/Lists.d.ts +8 -4
  16. package/src/lib/next/components/DotCMSBlockEditorRenderer/components/blocks/NoComponentProvided.d.ts +3 -0
  17. package/src/lib/{deprecated/components/BlockEditorRenderer → next/components/DotCMSBlockEditorRenderer/components}/blocks/Table.d.ts +3 -3
  18. package/src/lib/{deprecated/components/BlockEditorRenderer → next/components/DotCMSBlockEditorRenderer/components}/blocks/Texts.d.ts +23 -13
  19. package/src/lib/next/components/DotCMSBlockEditorRenderer/components/blocks/Video.d.ts +10 -0
  20. package/src/lib/{deprecated/components/DotEditableText/DotEditableText.d.ts → next/components/DotCMSEditableText/DotCMSEditableText.d.ts} +8 -6
  21. package/src/lib/{deprecated/components/DotEditableText → next/components/DotCMSEditableText}/utils.d.ts +9 -9
  22. package/src/lib/next/components/DotCMSLayoutBody/DotCMSLayoutBody.d.ts +5 -5
  23. package/src/lib/next/components/DotCMSLayoutBody/components/ErrorMessage.d.ts +1 -4
  24. package/src/lib/next/components/DotCMSShow/DotCMSShow.d.ts +2 -2
  25. package/src/lib/next/components/FallbackComponent/FallbackComponent.d.ts +6 -6
  26. package/src/lib/next/components/Row/Row.d.ts +1 -1
  27. package/src/lib/next/contexts/DotCMSPageContext.d.ts +2 -3
  28. package/src/lib/next/hooks/{useShowInUVE.d.ts → useDotCMSShowWhen.d.ts} +5 -5
  29. package/src/lib/next/hooks/useEditableDotCMSPage.d.ts +90 -0
  30. package/src/lib/next/hooks/useIsDevMode.d.ts +2 -5
  31. package/es.regexp.to-string.esm.js +0 -1878
  32. package/next.esm.d.ts +0 -1
  33. package/next.esm.js +0 -738
  34. package/src/lib/deprecated/components/BlockEditorRenderer/BlockEditorRenderer.d.ts +0 -37
  35. package/src/lib/deprecated/components/BlockEditorRenderer/blocks/Code.d.ts +0 -17
  36. package/src/lib/deprecated/components/BlockEditorRenderer/blocks/Contentlet.d.ts +0 -41
  37. package/src/lib/deprecated/components/BlockEditorRenderer/blocks/Image.d.ts +0 -8
  38. package/src/lib/deprecated/components/BlockEditorRenderer/blocks/Video.d.ts +0 -8
  39. package/src/lib/deprecated/components/Column/Column.d.ts +0 -19
  40. package/src/lib/deprecated/components/Container/Container.d.ts +0 -19
  41. package/src/lib/deprecated/components/DotcmsLayout/DotcmsLayout.d.ts +0 -34
  42. package/src/lib/deprecated/components/PageProvider/PageProvider.d.ts +0 -14
  43. package/src/lib/deprecated/components/Row/Row.d.ts +0 -26
  44. package/src/lib/deprecated/contexts/PageContext.d.ts +0 -8
  45. package/src/lib/deprecated/deprecated_api.d.ts +0 -7
  46. package/src/lib/deprecated/hooks/useCheckHaveContent.d.ts +0 -5
  47. package/src/lib/deprecated/hooks/useDotcmsEditor.d.ts +0 -13
  48. package/src/lib/deprecated/hooks/useDotcmsPageContext.d.ts +0 -9
  49. package/src/lib/deprecated/mocks/index.d.ts +0 -1
  50. package/src/lib/deprecated/mocks/mockPageContext.d.ts +0 -7
  51. package/src/lib/deprecated/models/blocks.interface.d.ts +0 -89
  52. package/src/lib/deprecated/models/content-node.interface.d.ts +0 -82
  53. package/src/lib/deprecated/models/index.d.ts +0 -127
  54. package/src/lib/deprecated/utils/utils.d.ts +0 -58
  55. package/src/lib/next/types.d.ts +0 -421
  56. package/src/lib/next/utils/index.d.ts +0 -136
  57. package/src/next.d.ts +0 -3
package/README.md CHANGED
@@ -1,177 +1,615 @@
1
- # @dotcms/react
1
+ # dotCMS React SDK
2
2
 
3
- `@dotcms/react` is the official set of React components and hooks designed to work seamlessly with dotCMS, making it easy to render dotCMS pages and use the page builder.
3
+ The `@dotcms/react` SDK is the DotCMS official React library. It empowers React developers to build powerful, editable websites and applications in no time.
4
4
 
5
- ## Features
5
+ ## Table of Contents
6
6
 
7
- - A collection of React components and hooks tailored to render dotCMS pages.
8
- - Streamlined integration with dotCMS page editor.
9
- - Improved development experience with comprehensive TypeScript typings.
7
+ - [Prerequisites & Setup](#prerequisites--setup)
8
+ - [Get a dotCMS Environment](#get-a-dotcms-environment)
9
+ - [Create a dotCMS API Key](#create-a-dotcms-api-key)
10
+ - [Configure The Universal Visual Editor App](#configure-the-universal-visual-editor-app)
11
+ - [Installation](#installation)
12
+ - [dotCMS Client Configuration](#dotcms-client-configuration)
13
+ - [Proxy Configuration for Static Assets](#proxy-configuration-for-static-assets)
14
+ - [Quickstart: Render a Page with dotCMS](#quickstart-render-a-page-with-dotcms)
15
+ - [Example Project](#example-project-)
16
+ - [SDK Reference](#sdk-reference)
17
+ - [DotCMSLayoutBody](#dotcmslayoutbody)
18
+ - [DotCMSShow](#dotcmsshow)
19
+ - [DotCMSBlockEditorRenderer](#dotcmsblockeditorrenderer)
20
+ - [DotCMSEditableText](#dotcmseditabletext)
21
+ - [useEditableDotCMSPage](#useeditabledotcmspage)
22
+ - [useDotCMSShowWhen](#usedotcmsshowwhen)
23
+ - [Troubleshooting](#troubleshooting)
24
+ - [Common Issues & Solutions](#common-issues--solutions)
25
+ - [Debugging Tips](#debugging-tips)
26
+ - [Version Compatibility](#version-compatibility)
27
+ - [Still Having Issues?](#still-having-issues)
28
+ - [dotCMS Support](#dotcms-support)
29
+ - [How To Contribute](#how-to-contribute)
30
+ - [Licensing Information](#licensing-information)
10
31
 
11
- ## Installation
32
+ ## Prerequisites & Setup
12
33
 
13
- Install the package via npm:
34
+ ### Get a dotCMS Environment
35
+
36
+ #### Version Compatibility
37
+
38
+ - **Recommended**: dotCMS Evergreen
39
+ - **Minimum**: dotCMS v25.05
40
+ - **Best Experience**: Latest Evergreen release
41
+
42
+ #### Environment Setup
43
+
44
+ **For Production Use:**
45
+
46
+ - ☁️ [Cloud hosting options](https://www.dotcms.com/pricing) - managed solutions with SLA
47
+ - 🛠️ [Self-hosted options](https://dev.dotcms.com/docs/current-releases) - deploy on your infrastructure
48
+
49
+ **For Testing & Development:**
50
+
51
+ - 🧑🏻‍💻 [dotCMS demo site](https://demo.dotcms.com/dotAdmin/#/public/login) - perfect for trying out the SDK
52
+ - 📘 [Learn how to use the demo site](https://dev.dotcms.com/docs/demo-site)
53
+ - 📝 Read-only access, ideal for building proof-of-concepts
54
+
55
+ **For Local Development:**
56
+
57
+ - 🐳 [Docker setup guide](https://github.com/dotCMS/core/tree/main/docker/docker-compose-examples/single-node-demo-site)
58
+ - 💻 [Local installation guide](https://dev.dotcms.com/docs/quick-start-guide)
59
+
60
+ ### Configure The Universal Visual Editor App
61
+
62
+ For a step-by-step guide on setting up the Universal Visual Editor, check out our [easy-to-follow instructions](https://dev.dotcms.com/docs/uve-headless-config) and get started in no time!
63
+
64
+ ### Create a dotCMS API Key
65
+
66
+ > [!TIP]
67
+ > Make sure your API Token has read-only permissions for Pages, Folders, Assets, and Content. Using a key with minimal permissions follows security best practices.
68
+
69
+ This integration requires an API Key with read-only permissions for security best practices:
70
+
71
+ 1. Go to the **dotCMS admin panel**.
72
+ 2. Click on **System** > **Users**.
73
+ 3. Select the user you want to create the API Key for.
74
+ 4. Go to **API Access Key** and generate a new key.
75
+
76
+ For detailed instructions, please refer to the [dotCMS API Documentation - Read-only token](https://dev.dotcms.com/docs/rest-api-authentication#ReadOnlyToken).
77
+
78
+ ### Install Dependencies
14
79
 
15
80
  ```bash
16
- npm install @dotcms/react
81
+ npm install @dotcms/react@latest
17
82
  ```
18
83
 
19
- Or using Yarn:
84
+ This will automatically install the required dependencies:
85
+ - `@dotcms/uve`: Enables interaction with the [Universal Visual Editor](https://dev.dotcms.com/docs/uve-headless-config) for real-time content editing
86
+ - `@dotcms/client`: Provides the core client functionality for fetching and managing dotCMS data
20
87
 
21
- ```bash
22
- yarn add @dotcms/react
88
+ ### dotCMS Client Configuration
89
+
90
+ ```typescript
91
+ import { createDotCMSClient } from '@dotcms/client';
92
+
93
+ type DotCMSClient = ReturnType<typeof createDotCMSClient>;
94
+
95
+ export const dotCMSClient: DotCMSClient = createDotCMSClient({
96
+ dotcmsUrl: 'https://your-dotcms-instance.com',
97
+ authToken: 'your-auth-token', // Optional for public content
98
+ siteId: 'your-site-id' // Optional site identifier/name
99
+ });
23
100
  ```
24
101
 
25
- ## Components
102
+ ### Proxy Configuration for Static Assets
26
103
 
27
- ### Deprecated: DotcmsLayout
104
+ Configure a proxy to leverage the powerful dotCMS image API, allowing you to resize and serve optimized images efficiently. This enhances application performance and improves user experience, making it a strategic enhancement for your project.
28
105
 
29
- **Important:** The `DotcmsLayout` component is deprecated. Please use the new [`DotCMSLayoutBody`](#DotCMSLayoutBody) component instead.
106
+ #### 1. Configure Vite
30
107
 
31
- #### Props
108
+ ```ts
109
+ // vite.config.ts
110
+ import { defineConfig } from 'vite';
111
+ import dns from 'node:dns';
32
112
 
33
- - **entity**: The context for a dotCMS page.
113
+ dns.setDefaultResultOrder('verbatim');
34
114
 
35
- #### Usage
115
+ export default defineConfig({
116
+ server: {
117
+ proxy: {
118
+ '/dA': {
119
+ target: 'your-dotcms-instance.com',
120
+ changeOrigin: true
121
+ }
122
+ }
123
+ }
124
+ });
125
+ ```
126
+
127
+ Learn more about Vite configuration [here](https://vitejs.dev/config/).
128
+
129
+ #### 2. Usage in Components
130
+
131
+ Once configured, image URLs in your components will automatically be proxied to your dotCMS instance:
132
+
133
+ >📚 Learn more about [Image Resizing and Processing in dotCMS with React](https://www.dotcms.com/blog/image-resizing-and-processing-in-dotcms-with-angular-and-nextjs).
134
+
135
+ ```typescript
136
+ // /components/my-dotcms-image.tsx
137
+ import type { DotCMSBasicContentlet } from '@dotcms/types';
138
+
139
+ export const MyDotCMSImageComponent = ({ inode, title }: DotCMSBasicContentlet) => {
140
+ return <img src={`/dA/${inode}`} alt={title} />;
141
+ }
142
+ ```
36
143
 
37
- ```javascript
38
- // Deprecated:
39
- import { DotcmsLayout } from '@dotcms/react';
144
+ ## Quickstart: Render a Page with dotCMS
40
145
 
41
- const MyPage = ({ entity }) => {
42
- return <DotcmsLayout entity={entity} />;
146
+ The following example demonstrates how to quickly set up a basic dotCMS page renderer in your React application. This example shows how to:
147
+
148
+ - Create a standalone component that renders a dotCMS page
149
+ - Set up dynamic component loading for different content types
150
+ - Handle both regular page viewing and editor mode
151
+ - Subscribe to real-time page updates when in the Universal Visual Editor
152
+
153
+ ```tsx
154
+ // /src/app/pages/dotcms-page.tsx
155
+ import { useState, useEffect } from 'react';
156
+ import { DotCMSLayoutBody, useEditableDotCMSPage } from '@dotcms/react';
157
+ import { DotCMSPageResponse } from '@dotcms/types';
158
+
159
+ import { dotCMSClient } from './dotCMSClient';
160
+ import { BlogComponent } from './BlogComponent';
161
+ import { ProductComponent } from './ProductComponent';
162
+
163
+ const COMPONENTS_MAP = {
164
+ Blog: BlogComponent,
165
+ Product: ProductComponent
166
+ };
167
+
168
+ const MyPage = () => {
169
+ const [response, setResponse] = useState<DotCMSPageResponse | null>(null);
170
+ const { pageAsset } = useEditableDotCMSPage(response);
171
+
172
+ useEffect(() => {
173
+ dotCMSClient.page.get('/').then((response) => {
174
+ setResponse(response);
175
+ });
176
+ }, []);
177
+
178
+ return <DotCMSLayoutBody page={pageAsset} components={COMPONENTS_MAP} mode="development" />;
43
179
  };
180
+
181
+ export default MyPage;
44
182
  ```
45
183
 
46
- ### `DotCMSLayoutBody`
184
+ ### Example Project 🚀
185
+
186
+ Looking to get started quickly? We've got you covered! Our [Next.js starter project](https://github.com/dotCMS/core/tree/main/examples/nextjs) is the perfect launchpad for your dotCMS + Next.js journey. This production-ready template demonstrates everything you need:
187
+
188
+ 📦 Fetch and render dotCMS pages with best practices
189
+ 🧩 Register and manage components for different content types
190
+ 🔍 Listing pages with search functionality
191
+ 📝 Detail pages for blogs
192
+ 📈 Image and assets optimization for better performance
193
+ ✨ Enable seamless editing via the Universal Visual Editor (UVE)
194
+ ⚡️ Leverage React's hooks and state management for optimal performance
195
+
196
+ > [!TIP]
197
+ > This starter project is more than just an example, it follows all our best practices. We highly recommend using it as the base for your next dotCMS + Next.js project!
198
+
199
+ ## SDK Reference
200
+
201
+ All components and hooks should be imported from `@dotcms/react`:
202
+
203
+ ### DotCMSLayoutBody
47
204
 
48
- The `DotCMSLayoutBody` component renders the layout body for a DotCMS page.
205
+ `DotCMSLayoutBody` is a component used to render the layout for a DotCMS page, supporting both production and development modes.
49
206
 
50
- #### Props
207
+ | Input | Type | Required | Default | Description |
208
+ | ------------ | ------------------------ | -------- | -------------- | ---------------------------------------------- |
209
+ | `page` | `DotCMSPageAsset` | ✅ | - | The page asset containing the layout to render |
210
+ | `components` | `DotCMSPageComponent` | ✅ | `{}` | [Map of content type → React component](#component-mapping) |
211
+ | `mode` | `DotCMSPageRendererMode` | ❌ | `'production'` | [Rendering mode ('production' or 'development')](#layout-body-modes) |
51
212
 
52
- - **page**: The DotCMS page asset containing the layout information.
53
- - **components**: A mapping of custom components for content rendering.
54
- - **mode** (optional): The renderer mode; defaults to `'production'`.
213
+ #### Client-Side Only Component
55
214
 
215
+ > ⚠️ **Important: This is a client-side React component.**
216
+ > `DotCMSLayoutBody` uses React features like `useContext`, `useEffect`, and `useState`.
217
+ > If you're using a framework that supports Server-Side Rendering (like **Next.js**, **Gatsby**, or **Astro**), you **must** mark the parent component with `"use client"` or follow your framework’s guidelines for using client-side components.
218
+ >
219
+ > 👉 [Learn more: Next.js – Client Components](https://nextjs.org/docs/getting-started/react-essentials#client-components)
56
220
 
57
221
  #### Usage
58
222
 
59
- ```javascript
223
+ ```tsx
224
+ import type { DotCMSPageAsset } from '@dotcms/types';
60
225
  import { DotCMSLayoutBody } from '@dotcms/react';
61
226
 
62
- const MyPage = ({ page }) => {
63
- return <DotCMSLayoutBody page={page} components={components} />;
227
+ import { MyBlogCard } from './MyBlogCard';
228
+ import { DotCMSProductComponent } from './DotCMSProductComponent';
229
+
230
+ const COMPONENTS_MAP = {
231
+ Blog: MyBlogCard,
232
+ Product: DotCMSProductComponent
233
+ };
234
+
235
+ const MyPage = ({ pageAsset }: DotCMSPageResponse) => {
236
+ return <DotCMSLayoutBody page={pageAsset} components={COMPONENTS_MAP} />;
237
+ };
238
+ ```
239
+
240
+ #### Layout Body Modes
241
+
242
+ - `production`: Performance-optimized mode that only renders content with explicitly mapped components, leaving unmapped content empty.
243
+ - `development`: Debug-friendly mode that renders default components for unmapped content types and provides visual indicators and console logs for empty containers and missing mappings.
244
+
245
+ #### Component Mapping
246
+
247
+ The `DotCMSLayoutBody` component uses a `components` prop to map content type variable names to React components. This allows you to render different components for different content types. Example:
248
+
249
+ ```typescript
250
+ const DYNAMIC_COMPONENTS = {
251
+ Blog: MyBlogCard,
252
+ Product: DotCMSProductComponent
64
253
  };
65
254
  ```
66
255
 
256
+ - Keys (e.g., `Blog`, `Product`): Match your [content type variable names](https://dev.dotcms.com/docs/content-types#VariableNames) in dotCMS
257
+ - Values: Dynamic imports of your React components that render each content type
258
+ - Supports lazy loading through dynamic imports
259
+ - Components must be standalone or declared in a module
67
260
 
68
- ### `BlockEditorRenderer`
261
+ > [!TIP]
262
+ > Always use the exact content type variable name from dotCMS as the key. You can find this in the Content Types section of your dotCMS admin panel.
69
263
 
70
- The `BlockEditorRenderer` component renders the content of a Block Editor Content Type from dotCMS.
71
- [More information of Block Editor Content Type](https://dev.dotcms.com/docs/block-editor)
72
264
 
73
- #### Props
265
+ ### DotCMSEditableText
74
266
 
267
+ `DotCMSEditableText` is a component for inline editing of text fields in dotCMS, supporting plain text, text area, and WYSIWYG fields.
75
268
 
76
- | Prop | Type | Description |
77
- |------|------|-------------|
78
- | `blocks` | `Block` | The block editor content structure to render. |
79
- | `customRenderers` | `CustomRenderer` | Optional custom renderers for specific block types. |
80
- | `className` | `string` | Optional CSS class name to apply to the container. |
81
- | `style` | `React.CSSProperties` | Optional inline styles to apply to the container. |
82
- | `contentlet` | `DotCMSContentlet` | Contentlet object containing the field to be edited. Required when editable is true. |
83
- | `fieldName` | `string` | Name of the field in the contentlet that contains the block editor content. Required when editable is true. |
269
+ | Input | Type | Required | Description |
270
+ | ------------ | ------------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
271
+ | `contentlet` | `T extends DotCMSBasicContentlet` | | The contentlet containing the editable field |
272
+ | `fieldName` | `keyof T` | | Name of the field to edit, which must be a valid key of the contentlet type `T` |
273
+ | `mode` | `'plain' \| 'full'` | ❌ | `plain` (default): Support text editing. Does not show style controls. <br/> `full`: Enables a bubble menu with style options. This mode only works with [`WYSIWYG` fields](https://dev.dotcms.com/docs/the-wysiwyg-field). |
274
+ | `format` | `'text' \| 'html'` | | `text` (default): Renders HTML tags as plain text <br/> `html`: Interprets and renders HTML markup |
84
275
 
85
- For a more in-depth explanation of BlockEditorRenderer, visit the [documentation](./src/lib/deprecated/components/BlockEditorRenderer/BlockEditorRenderer.md).
276
+ #### Usage
86
277
 
87
- ## Hooks
278
+ ```tsx
279
+ import type { DotCMSBasicContentlet } from '@dotcms/types';
280
+ import { DotCMSEditableText } from '@dotcms/react';
281
+
282
+ const MyBannerComponent = ({ contentlet }: { contentlet: DotCMSBasicContentlet }) => {
283
+ const { inode, title, link } = contentlet;
284
+
285
+ return (
286
+ <div className="flex overflow-hidden relative justify-center items-center w-full h-96 bg-gray-200">
287
+ <img className="object-cover w-full" src={`/dA/${inode}`} alt={title} />
288
+ <div className="flex absolute inset-0 flex-col justify-center items-center p-4 text-center text-white">
289
+ <h2 className="mb-2 text-6xl font-bold text-shadow">
290
+ <DotCMSEditableText fieldName="title" contentlet={contentlet} />
291
+ </h2>
292
+ <a
293
+ href={link}
294
+ className="p-4 text-xl bg-red-400 rounded-sm transition duration-300 hover:bg-red-500">
295
+ See more
296
+ </a>
297
+ </div>
298
+ </div>
299
+ );
300
+ };
301
+
302
+ export default MyBannerComponent;
303
+ ```
88
304
 
89
- ### `useDotcmsPageContext`
305
+ #### Editor Integration
90
306
 
91
- A custom React hook that provides access to the `PageProviderContext`.
307
+ - Detects UVE edit mode and enables inline TinyMCE editing
308
+ - Triggers a `Save` [workflow action](https://dev.dotcms.com/docs/workflows) on blur without needing full content dialog.
92
309
 
93
- #### Returns
310
+ #### DotCMSBlockEditorRenderer
94
311
 
95
- - `PageProviderContext | null`: The context value or `null` if it's not available.
312
+ `DotCMSBlockEditorRenderer` is a component for rendering [Block Editor](https://dev.dotcms.com/docs/block-editor) content from dotCMS with support for custom block renderers.
313
+
314
+ | Input | Type | Required | Description |
315
+ | ----------------- | -------------------- | -------- | ---------------------------------------------------------------------------------------------------------- |
316
+ | `blocks` | `BlockEditorContent` | ✅ | The [Block Editor](https://dev.dotcms.com/docs/block-editor) content to render |
317
+ | `customRenderers` | `CustomRenderers` | ❌ | Custom rendering functions for specific [block types](https://dev.dotcms.com/docs/block-editor#BlockTypes) |
318
+ | `className` | `string` | ❌ | CSS class to apply to the container |
319
+ | `style` | `CSSProperties` | ❌ | Inline styles for the container |
96
320
 
97
321
  #### Usage
98
322
 
99
- ```javascript
100
- import { useDotcmsPageContext } from '@dotcms/react';
323
+ ```tsx
324
+ import type { DotCMSBasicContentlet } from '@dotcms/types';
325
+ import { DotCMSBlockEditorRenderer } from '@dotcms/react';
101
326
 
102
- const MyComponent = () => {
103
- const context = useDotcmsPageContext();
104
- // Use the context
327
+ import { MyCustomBannerBlock } from './MyCustomBannerBlock';
328
+ import { MyCustomH1 } from './MyCustomH1';
329
+
330
+ const CUSTOM_RENDERERS = {
331
+ customBannerBlock: MyCustomBannerBlock,
332
+ h1: MyCustomH1
333
+ };
334
+
335
+ const DetailPage = ({ contentlet }: { contentlet: DotCMSBasicContentlet }) => {
336
+ return (
337
+ <DotCMSBlockEditorRenderer
338
+ blocks={contentlet['YOUR_BLOCK_EDITOR_FIELD']}
339
+ customRenderers={CUSTOM_RENDERERS}
340
+ />
341
+ );
105
342
  };
106
343
  ```
107
344
 
108
- ### `usePageEditor`
345
+ #### Recommendations
109
346
 
110
- A custom React hook that sets up the page editor for a dotCMS page.
347
+ - Should not be used with [`DotCMSEditableText`](#dotcmseditabletext)
348
+ - Take into account the CSS cascade can affect the look and feel of your blocks.
349
+ - `DotCMSBlockEditorRenderer` only works with [Block Editor fields](https://dev.dotcms.com/docs/block-editor). For other fields, use [`DotCMSEditableText`](#dotcmseditabletext).
111
350
 
112
- #### Parameters
351
+ 📘 For advanced examples, customization options, and best practices, refer to the [DotCMSBlockEditorRenderer README](https://github.com/dotCMS/core/tree/master/core-web/libs/sdk/react/src/lib/components/DotCMSBlockEditorRenderer).
113
352
 
114
- - **props**: `PageEditorOptions` - The options for the page editor. Includes a `reloadFunction` and a `pathname`.
353
+ #### DotCMSShow
115
354
 
116
- #### Returns
355
+ `DotCMSShow` is a component for conditionally rendering content based on the current UVE mode. Useful for mode-based behaviors outside of render logic.
117
356
 
118
- - `React.RefObject<HTMLDivElement>[]`: A reference to the rows of the page.
357
+ | Input | Type | Required | Description |
358
+ | ---------- | ----------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
359
+ | `children` | `ReactNode` | ✅ | Content to be conditionally rendered |
360
+ | `when` | `UVE_MODE` | ✅ | The `UVE` mode when content should be displayed: <br/> `UVE_MODE.EDIT`: Only visible in edit mode <br/> `UVE_MODE.PREVIEW`: Only visible in preview mode <br/> `UVE_MODE.PUBLISHED`: Only visible in published mode |
119
361
 
120
362
  #### Usage
121
363
 
122
- ```javascript
123
- import { usePageEditor } from '@dotcms/react';
364
+ ```tsx
365
+ import { UVE_MODE } from '@dotcms/types';
366
+ import { DotCMSShow } from '@dotcms/react';
124
367
 
125
- const MyEditor = () => {
126
- const rowsRef = usePageEditor({ pathname: '/my-page' });
127
- // Use the rowsRef
368
+ const MyComponent = () => {
369
+ return (
370
+ <DotCMSShow when={UVE_MODE.EDIT}>
371
+ <div>This will only render in UVE EDIT mode</div>
372
+ </DotCMSShow>
373
+ );
128
374
  };
129
375
  ```
130
376
 
131
- ## Context Providers
377
+ 📚 Learn more about the `UVE_MODE` enum in the [dotCMS UVE Package Documentation](https://dev.dotcms.com/docs/uve).
378
+
379
+ ### useEditableDotCMSPage
380
+
381
+ `useEditableDotCMSPage` is a hook that enables real-time page updates when using the Universal Visual Editor.
132
382
 
133
- ### `PageProvider`
383
+ | Param | Type | Required | Description |
384
+ | -------------- | -------------------- | -------- | --------------------------------------------- |
385
+ | `pageResponse` | `DotCMSPageResponse` | ✅ | The page data object from `client.page.get()` |
134
386
 
135
- A functional component that provides a context for a dotCMS page.
387
+ #### Service Lifecycle & Operations
136
388
 
137
- #### Props
389
+ When you use the hook, it:
138
390
 
139
- - **entity**: The entity representing the page's data.
140
- - **children**: The children components.
391
+ 1. Initializes the UVE with your page data
392
+ 2. Sets up communication channels with the editor
393
+ 3. Tracks content changes in real-time
394
+ 4. Updates your page automatically when:
395
+ - Content is edited inline
396
+ - Blocks are added or removed
397
+ - Layout changes are made
398
+ - Components are moved
399
+ 5. Cleans up all listeners and connections on destroy
141
400
 
142
401
  #### Usage
143
402
 
144
- ```javascript
145
- import { PageProvider } from '@dotcms/react';
403
+ ```tsx
404
+ 'use client';
146
405
 
147
- const MyApp = ({ entity }) => {
148
- return <PageProvider entity={entity}>{/* children */}</PageProvider>;
406
+ import { useEditableDotCMSPage, DotCMSLayoutBody } from '@dotcms/react';
407
+ import type { DotCMSPageResponse } from '@dotcms/types';
408
+
409
+ const COMPONENTS_MAP = {
410
+ Blog: BlogComponent,
411
+ Product: ProductComponent
149
412
  };
413
+
414
+ export function DotCMSPage({ pageResponse }: { pageResponse: DotCMSPageResponse }) {
415
+ const { pageAsset } = useEditableDotCMSPage(pageResponse);
416
+ return <DotCMSLayoutBody pageAsset={pageAsset} components={COMPONENTS_MAP} />;
417
+ }
150
418
  ```
151
419
 
152
- ## Contributing
420
+ #### useDotCMSShowWhen
421
+
422
+ `useDotCMSShowWhen` is a hook for conditionally showing content based on the current UVE mode. Useful for mode-based behaviors outside of render logic.
423
+
424
+ | Param | Type | Required | Description |
425
+ | ------ | ---------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
426
+ | `when` | `UVE_MODE` | ✅ | The `UVE` mode when content should be displayed: <br/> `UVE_MODE.EDIT`: Only visible in edit mode <br/> `UVE_MODE.PREVIEW`: Only visible in preview mode <br/> `UVE_MODE.PUBLISHED`: Only visible in published mode |
427
+
428
+ #### Usage
429
+
430
+ ```tsx
431
+ import { UVE_MODE } from '@dotcms/types';
432
+ import { useDotCMSShowWhen } from '@dotcms/react';
433
+
434
+ const MyEditButton = () => {
435
+ const isEditMode = useDotCMSShowWhen(UVE_MODE.EDIT); // returns a boolean
436
+
437
+ if (isEditMode) {
438
+ return <button>Edit</button>;
439
+ }
440
+
441
+ return null;
442
+ };
443
+ ```
444
+
445
+ ## Troubleshooting
446
+
447
+ ### Common Issues & Solutions
448
+
449
+ #### Universal Visual Editor (UVE)
450
+
451
+ 1. **UVE Not Loading**: Page loads but UVE controls are not visible
452
+ - **Possible Causes**:
453
+ - Incorrect UVE configuration
454
+ - Missing API token permissions
455
+ - Missing the `DotCMSEditablePageService` call to enable UVE.
456
+ - **Solutions**:
457
+ - Verify UVE app configuration in dotCMS admin
458
+ - Check API token has edit permissions
459
+ - Ensure `dotcmsUrl` matches your instance URL exactly
460
+
461
+ #### Missing Content
462
+
463
+ 1. **Components Not Rendering**: Empty spaces where content should appear
464
+
465
+ - **Possible Causes**:
466
+ - Missing component mappings
467
+ - Incorrect content type variable names
468
+ - **Solutions**:
469
+ - Check component registration in `components` prop
470
+ - Verify content type variable names match exactly
471
+ - Enable `development` mode for detailed logging
472
+
473
+ 2. **Asset Loading Issues**: Images or files not loading
474
+ - **Possible Causes**:
475
+ - Proxy configuration issues
476
+ - CORS restrictions
477
+ - **Solutions**:
478
+ - Verify proxy settings in `vite.config.ts`
479
+ - Check network tab for CORS errors
480
+ - Ensure `/dA` path is properly configured
481
+
482
+ #### Development Setup
483
+
484
+ 1. **Build Errors**: `npm install` fails
485
+
486
+ - **Solutions**:
487
+ - Clear npm cache: `npm cache clean --force`
488
+ - Delete `node_modules` and reinstall
489
+ - Verify Node.js version compatibility
490
+
491
+ 2. **Runtime Errors**: Console errors about missing imports or components not rendering
492
+ - **Solutions**:
493
+ - Check all imports are from `@dotcms/react`
494
+ - Verify all peer dependencies are installed
495
+ - Update to latest compatible versions
496
+
497
+ #### Next.js App Router Integration
498
+
499
+ 1. **Server Component Errors**: Errors about React class components in Server Components
500
+
501
+ - **Possible Causes**:
502
+ - Using dotCMS components directly in Server Components
503
+ - Missing 'use client' directive
504
+ - Incorrect data fetching pattern
505
+ - **Solutions**:
506
+
507
+ 1. Split your code into Server and Client Components:
508
+
509
+ ```tsx
510
+ // app/page.tsx (Server Component)
511
+ import { DotCMSPage } from '@/components/DotCMSPage';
512
+ import { dotCMSClient } from '@/lib/dotCMSClient';
513
+
514
+ export default async function Page() {
515
+ const pageResponse = await dotCMSClient.page.get('/index');
516
+ return <DotCMSPage pageResponse={pageResponse} />;
517
+ }
518
+ ```
519
+
520
+ ```tsx
521
+ // components/DotCMSPage.tsx (Client Component)
522
+ 'use client';
523
+
524
+ import { useEditableDotCMSPage, DotCMSLayoutBody } from '@dotcms/react';
525
+ import type { DotCMSPageResponse } from '@dotcms/types';
526
+
527
+ const COMPONENTS_MAP = {
528
+ Blog: BlogComponent,
529
+ Product: ProductComponent
530
+ };
531
+
532
+ export function DotCMSPage({ pageResponse }: { pageResponse: DotCMSPageResponse }) {
533
+ const { pageAsset } = useEditableDotCMSPage(pageResponse);
534
+ return <DotCMSLayoutBody pageAsset={pageAsset} components={COMPONENTS_MAP} />;
535
+ }
536
+ ```
537
+
538
+ 2. Always fetch data in Server Components for better performance
539
+ 3. Use Client Components only for rendering dotCMS interactive components
540
+
541
+ ### Debugging Tips
542
+
543
+ 1. **Enable Development Mode**
544
+
545
+ ```typescript
546
+ <dotcms-layout-body
547
+ [page]="pageAsset()"
548
+ [components]="components()"
549
+ mode="development"
550
+ />
551
+ ```
552
+
553
+ This will:
554
+
555
+ - Show detailed error messages
556
+ - Highlight unmapped components
557
+ - Log component lifecycle events
558
+
559
+ 2. **Check Browser Console**
560
+
561
+ - Check for errors in the browser console
562
+ - Check for errors in the browser network tab
563
+
564
+ 3. **Network Monitoring**
565
+ - Use browser dev tools to monitor API calls
566
+ - Check for 401/403 errors (auth issues)
567
+ - Verify asset loading paths
568
+
569
+ ### Still Having Issues?
570
+
571
+ If you're still experiencing problems after trying these solutions:
572
+
573
+ 1. Search existing [GitHub issues](https://github.com/dotCMS/core/issues)
574
+ 2. Ask questions on the [community forum](https://community.dotcms.com/) to engage with other users.
575
+ 3. Create a new issue with:
576
+ - Detailed reproduction steps
577
+ - Environment information
578
+ - Error messages
579
+ - Code samples
580
+
581
+ ## dotCMS Support
582
+
583
+ We offer multiple channels to get help with the dotCMS React SDK:
584
+
585
+ - **GitHub Issues**: For bug reports and feature requests, please [open an issue](https://github.com/dotCMS/core/issues/new/choose) in the GitHub repository.
586
+ - **Community Forum**: Join our [community discussions](https://community.dotcms.com/) to ask questions and share solutions.
587
+ - **Stack Overflow**: Use the tag `dotcms-react` when posting questions.
588
+ - **Enterprise Support**: Enterprise customers can access premium support through the [dotCMS Support Portal](https://helpdesk.dotcms.com/support/).
589
+
590
+ When reporting issues, please include:
153
591
 
154
- GitHub pull requests are the preferred method to contribute code to dotCMS. Before any pull requests can be accepted, an automated tool will ask you to agree to the [dotCMS Contributor's Agreement](https://gist.github.com/wezell/85ef45298c48494b90d92755b583acb3).
592
+ - SDK version you're using
593
+ - React version
594
+ - Minimal reproduction steps
595
+ - Expected vs. actual behavior
155
596
 
156
- ## Licensing
597
+ ## How To Contribute
157
598
 
158
- dotCMS comes in multiple editions and as such is dual licensed. The dotCMS Community Edition is licensed under the GPL 3.0 and is freely available for download, customization and deployment for use within organizations of all stripes. dotCMS Enterprise Editions (EE) adds a number of enterprise features and is available via a supported, indemnified commercial license from dotCMS. For the differences between the editions, see [the feature page](http://dotcms.com/cms-platform/features).
599
+ GitHub pull requests are the preferred method to contribute code to dotCMS. We welcome contributions to the DotCMS UVE SDK! If you'd like to contribute, please follow these steps:
159
600
 
160
- ## Support
601
+ 1. Fork the repository [dotCMS/core](https://github.com/dotCMS/core)
602
+ 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
603
+ 3. Commit your changes (`git commit -m 'Add some amazing feature'`)
604
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
605
+ 5. Open a Pull Request
161
606
 
162
- If you need help or have any questions, please [open an issue](https://github.com/dotCMS/core/issues/new/choose) in the GitHub repository.
607
+ Please ensure your code follows the existing style and includes appropriate tests.
163
608
 
164
- ## Documentation
609
+ ## Licensing Information
165
610
 
166
- Always refer to the official [DotCMS documentation](https://www.dotcms.com/docs/latest/) for comprehensive guides and API references.
611
+ dotCMS comes in multiple editions and as such is dual-licensed. The dotCMS Community Edition is licensed under the GPL 3.0 and is freely available for download, customization, and deployment for use within organizations of all stripes. dotCMS Enterprise Editions (EE) adds several enterprise features and is available via a supported, indemnified commercial license from dotCMS. For the differences between the editions, see [the feature page](http://www.dotcms.com/cms-platform/features).
167
612
 
168
- ## Getting Help
613
+ This SDK is part of dotCMS's dual-licensed platform (GPL 3.0 for Community, commercial license for Enterprise).
169
614
 
170
- | Source | Location |
171
- | --------------- | ------------------------------------------------------------------- |
172
- | Installation | [Installation](https://dotcms.com/docs/latest/installation) |
173
- | Documentation | [Documentation](https://dotcms.com/docs/latest/table-of-contents) |
174
- | Videos | [Helpful Videos](http://dotcms.com/videos/) |
175
- | Forums/Listserv | [via Google Groups](https://groups.google.com/forum/#!forum/dotCMS) |
176
- | Twitter | @dotCMS |
177
- | Main Site | [dotCMS.com](https://dotcms.com/) |
615
+ [Learn more ](https://www.dotcms.com)at [dotcms.com](https://www.dotcms.com).