Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Base64Png Editor GetContent/SetContent/GetPreview
const getContent = useCallback(() => {
return editorContent;
}, [editorContent]);
const setContent = useCallback((path: string, content: string) => {
setOriginalContent(content);
}, []);
const getPreview = useCallback(() => {
const width = imageRef.current!.width;
const height = imageRef.current!.height;
return `
<svg version="1.1" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">
<image width="${width}" height="${height}" xlink:href="data:image/png;base64,${editorContent}" />
</svg>`;
}, [editorContent]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment