@payloadcms/live-preview-react 0.1.0 → 0.1.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 (2) hide show
  1. package/package.json +8 -7
  2. package/src/index.ts +0 -43
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/live-preview-react",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "The official live preview React SDK for Payload",
5
5
  "repository": "https://github.com/payloadcms/payload",
6
6
  "license": "MIT",
@@ -9,14 +9,15 @@
9
9
  "main": "./dist/index.js",
10
10
  "types": "./dist/index.d.ts",
11
11
  "dependencies": {
12
- "react": "18.2.0",
13
- "@payloadcms/live-preview": "0.1.0"
12
+ "@payloadcms/live-preview": "0.1.2"
14
13
  },
15
14
  "devDependencies": {
16
- "@types/node": "20.5.7",
17
- "@types/react": "18.2.15",
18
- "payload": "2.0.0-beta.31",
19
- "@payloadcms/eslint-config": "0.0.1"
15
+ "@types/react": "^18.2.0",
16
+ "@payloadcms/eslint-config": "0.0.1",
17
+ "payload": "2.0.3"
18
+ },
19
+ "peerDependencies": {
20
+ "react": "^16.8.0 || ^17.0.0 || ^18.0.0"
20
21
  },
21
22
  "exports": null,
22
23
  "publishConfig": {
package/src/index.ts DELETED
@@ -1,43 +0,0 @@
1
- import { subscribe, unsubscribe } from '@payloadcms/live-preview'
2
- import { useCallback, useEffect, useState } from 'react'
3
-
4
- // To prevent the flicker of missing data on initial load,
5
- // you can pass in the initial page data from the server
6
- // To prevent the flicker of stale data while the post message is being sent,
7
- // you can conditionally render loading UI based on the `isLoading` state
8
-
9
- export const useLivePreview = <T extends any>(props: {
10
- depth?: number
11
- initialData: T
12
- serverURL: string
13
- }): {
14
- data: T
15
- isLoading: boolean
16
- } => {
17
- const { depth = 0, initialData, serverURL } = props
18
- const [data, setData] = useState<T>(initialData)
19
- const [isLoading, setIsLoading] = useState<boolean>(true)
20
-
21
- const onChange = useCallback((mergedData) => {
22
- setData(mergedData)
23
- setIsLoading(false)
24
- }, [])
25
-
26
- useEffect(() => {
27
- const subscription = subscribe({
28
- callback: onChange,
29
- depth,
30
- initialData,
31
- serverURL,
32
- })
33
-
34
- return () => {
35
- unsubscribe(subscription)
36
- }
37
- }, [serverURL, onChange, depth, initialData])
38
-
39
- return {
40
- data,
41
- isLoading,
42
- }
43
- }