Appearance
useDrauu
Reactive instance for drauu.
Demo
Install
bash
npm i drauu@^1Usage
tsx
import { useDrauu } from '@reause/integrations'
import { useRef } from 'react'
const target = useRef<SVGSVGElement>(null)
const { undo, redo, canUndo, canRedo, clear, brush, setBrush } = useDrauu(target, {
brush: { color: 'black', size: 3 },
})
// `brush` is the current brush value; `setBrush` is its paired setter and
// updates both the returned value and the mounted instance
setBrush(prev => ({ ...prev, color: '#ef4444' }))
return <svg ref={target} />Type Declarations
ts
export type UseDrauuOptions = Omit<Options, 'el'>
export interface UseDrauuReturn {
drauuInstance: Drauu | undefined;
load: (svg: string) => void;
dump: () => string | undefined;
clear: () => void;
cancel: () => void;
undo: () => boolean | undefined;
redo: () => boolean | undefined;
canUndo: boolean;
canRedo: boolean;
brush: Brush;
setBrush: Dispatch<SetStateAction<Brush>>;
onChanged: ListenerOn<() => void>;
onCommitted: ListenerOn<(node: SVGElement | undefined) => void>;
onStart: ListenerOn<() => void>;
onEnd: ListenerOn<() => void>;
onCanceled: ListenerOn<() => void>;
}
type DrauuTarget = RefObject<MaybeElement>
export function useDrauu(target: DrauuTarget, options?: UseDrauuOptions): UseDrauuReturn