diff --git a/.changeset/smooth-guests-count.md b/.changeset/smooth-guests-count.md new file mode 100644 index 0000000000..8166530a7b --- /dev/null +++ b/.changeset/smooth-guests-count.md @@ -0,0 +1,5 @@ +--- +'@ice/cache-canvas': patch +--- + +feat: add storage for canvas diff --git a/examples/cavans-project/src/pages/home.tsx b/examples/cavans-project/src/pages/home.tsx index b8d8acf7ee..b27b8efec8 100644 --- a/examples/cavans-project/src/pages/home.tsx +++ b/examples/cavans-project/src/pages/home.tsx @@ -24,13 +24,15 @@ export default function Home() { setTimeout(() => { console.log('canvas paint ready!'); resolve(true); - }, 5000); + }, 10000); }); }; + return ( <>

Home Page

Promise; useCache?: Boolean; getSnapshot?: () => String; @@ -50,6 +54,7 @@ export const CacheCanvas = forwardRef((props: CacheCanvasProps, ref) => { fallback, style, className, + bizID = '', ...rest } = props; @@ -69,9 +74,11 @@ export const CacheCanvas = forwardRef((props: CacheCanvasProps, ref) => { } // Cache base64 string when canvas rendered. if (renderedCanvas && strBase64) { - Storage.setItem(cacheKey, strBase64); + Storage.setItem(cacheKey, strBase64, { + bizID, + }); } - }, [id, renderedCanvas, cacheKey, getSnapshot]); + }, [id, renderedCanvas, cacheKey, getSnapshot, bizID]); useImperativeHandle(ref, () => ({ cacheCanvasToStorage: cacheCanvasFunc, @@ -126,13 +133,13 @@ export const CacheCanvas = forwardRef((props: CacheCanvasProps, ref) => { { (typeof fallback === 'function') && (
{ fallback() @@ -141,8 +148,29 @@ export const CacheCanvas = forwardRef((props: CacheCanvasProps, ref) => { }