olexander_dan

Untitled

Jun 13th, 2024
739
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TypeScript 1.28 KB | Software | 0 0
  1. const MockStorage = () => {
  2.  
  3.   const anno = useAnnotator<RecogitoW3CTextAnnotator>();
  4.  
  5.   const [count, setCount] = useState(0);
  6.  
  7.   useEffect(() => {
  8.     if (!anno) return;
  9.  
  10.     const handleCreateAnnotation = (annotation: W3CTextAnnotation) => console.log('create', annotation);
  11.     anno.on('createAnnotation', handleCreateAnnotation);
  12.  
  13.     const handleDeleteAnnotation = (annotation: W3CTextAnnotation) => console.log('delete', annotation);
  14.     anno.on('deleteAnnotation', handleDeleteAnnotation);
  15.  
  16.     const handleSelectionChanged = (annotations: W3CTextAnnotation[]) => console.log('selection changed', annotations);
  17.     anno.on('selectionChanged', handleSelectionChanged);
  18.  
  19.     const handleUpdateAnnotation = (annotation: W3CTextAnnotation, previous: W3CTextAnnotation) => console.log('update', annotation, previous);
  20.     anno.on('updateAnnotation', handleUpdateAnnotation);
  21.  
  22.     return () => {
  23.       anno.off('createAnnotation', handleCreateAnnotation);
  24.       anno.off('deleteAnnotation', handleDeleteAnnotation);
  25.       anno.off('selectionChanged', handleSelectionChanged);
  26.       anno.off('updateAnnotation', handleUpdateAnnotation);
  27.     };
  28.   }, [anno, count]);
  29.  
  30.   return <>
  31.     <button onClick={() => setCount(c => c + 1)}>
  32.       Trigger {count}
  33.     </button>
  34.   </>;
  35.  
  36. };
Advertisement
Add Comment
Please, Sign In to add comment