import * as React from 'react'; import Cropper from 'react-cropper'; // If you choose not to use import, you need to assign Cropper to default // var Cropper = require('react-cropper').default /** * initializes cropper with string reference */ class Demo extends React.Component { crop() { // image in dataUrl console.log((this.refs['cropper'] as any).getCroppedCanvas().toDataURL()); } render() { return ( ); } } /** * initializes cropper with ref using useRef hook */ const DemoFunctionComponent: React.FunctionComponent = () => { const cropper = React.useRef(); const crop = () => { console.log(cropper.current?.getData(true)); }; return ( ); }; function testCropperRef() { const refIsWorking = ( { // $ExpectError el can be null el.getCroppedCanvas(); if (el !== null) { // el is a cropperjs element el.getCroppedCanvas(); // el is also a React.Component instance el.props; } }} /> ); const refIsOptional = ; }