@payloadcms/live-preview-react
Advanced tools
Comparing version 3.0.0-beta.16 to 3.0.0-beta.27
@@ -1,10 +0,3 @@ | ||
export declare const useLivePreview: <T extends unknown>(props: { | ||
apiRoute?: string; | ||
depth?: number; | ||
initialData: T; | ||
serverURL: string; | ||
}) => { | ||
data: T; | ||
isLoading: boolean; | ||
}; | ||
export { RefreshRouteOnSave } from './RefreshRouteOnSave.js'; | ||
export { useLivePreview } from './useLivePreview.js'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,46 +0,4 @@ | ||
import { ready, subscribe, unsubscribe } from '@payloadcms/live-preview'; | ||
import { useCallback, useEffect, useRef, useState } from 'react'; | ||
// To prevent the flicker of missing data on initial load, | ||
// you can pass in the initial page data from the server | ||
// To prevent the flicker of stale data while the post message is being sent, | ||
// you can conditionally render loading UI based on the `isLoading` state | ||
export const useLivePreview = (props)=>{ | ||
const { apiRoute, depth, initialData, serverURL } = props; | ||
const [data, setData] = useState(initialData); | ||
const [isLoading, setIsLoading] = useState(true); | ||
const hasSentReadyMessage = useRef(false); | ||
const onChange = useCallback((mergedData)=>{ | ||
setData(mergedData); | ||
setIsLoading(false); | ||
}, []); | ||
useEffect(()=>{ | ||
const subscription = subscribe({ | ||
apiRoute, | ||
callback: onChange, | ||
depth, | ||
initialData, | ||
serverURL | ||
}); | ||
if (!hasSentReadyMessage.current) { | ||
hasSentReadyMessage.current = true; | ||
ready({ | ||
serverURL | ||
}); | ||
} | ||
return ()=>{ | ||
unsubscribe(subscription); | ||
}; | ||
}, [ | ||
serverURL, | ||
onChange, | ||
depth, | ||
initialData, | ||
apiRoute | ||
]); | ||
return { | ||
data, | ||
isLoading | ||
}; | ||
}; | ||
export { RefreshRouteOnSave } from './RefreshRouteOnSave.js'; | ||
export { useLivePreview } from './useLivePreview.js'; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@payloadcms/live-preview-react", | ||
"version": "3.0.0-beta.16", | ||
"version": "3.0.0-beta.27", | ||
"description": "The official live preview React SDK for Payload", | ||
"homepage": "https://payloadcms.com", | ||
"repository": { | ||
@@ -11,7 +12,16 @@ "type": "git", | ||
"license": "MIT", | ||
"homepage": "https://payloadcms.com", | ||
"author": "Payload CMS, Inc.", | ||
"author": "Payload <dev@payloadcms.com> (https://payloadcms.com)", | ||
"type": "module", | ||
"exports": { | ||
".": { | ||
"import": "./dist/index.js", | ||
"require": "./dist/index.js", | ||
"types": "./dist/index.d.ts" | ||
} | ||
}, | ||
"main": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"type": "module", | ||
"files": [ | ||
"dist" | ||
], | ||
"dependencies": { | ||
@@ -22,4 +32,4 @@ "@payloadcms/live-preview": "^0.x" | ||
"@types/react": "18.2.74", | ||
"@payloadcms/eslint-config": "3.0.0-beta.16", | ||
"payload": "3.0.0-beta.16" | ||
"payload": "3.0.0-beta.27", | ||
"@payloadcms/eslint-config": "1.1.1" | ||
}, | ||
@@ -29,15 +39,5 @@ "peerDependencies": { | ||
}, | ||
"exports": { | ||
".": { | ||
"import": "./dist/index.js", | ||
"require": "./dist/index.js", | ||
"types": "./dist/index.d.ts" | ||
} | ||
}, | ||
"publishConfig": { | ||
"registry": "https://registry.npmjs.org/" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
@@ -44,0 +44,0 @@ "build": "pnpm copyfiles && pnpm build:swc && pnpm build:types", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11075
13
107