@dotcms/react 0.0.1-beta.4 → 0.0.1-beta.40

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