UNPKG

@afzalimdad9/react-file-preview

Version:

The url previewer is built using native html elements for previewing url of files of the following type

29 lines 1.14 kB
import { __makeTemplateObject } from "tslib"; import { jsx as _jsx } from "react/jsx-runtime"; import { useEffect, useState } from 'react'; import styled from 'styled-components'; var Container = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n width: 100%;\n height: 100%;\n overflow: auto;\n"], ["\n width: 100%;\n height: 100%;\n overflow: auto;\n"]))); export default function TextViewer(_a) { var src = _a.src, onLoad = _a.onLoad, onError = _a.onError; var _b = useState(''), data = _b[0], setData = _b[1]; useEffect(function () { var req = new XMLHttpRequest(); req.open('GET', src, true); req.onload = function (e) { if (req.status >= 300) { onError(e); } else { setData(req.response); onLoad(true); } }; req.send(); return function () { req.abort(); }; }, [src, onLoad, onError]); return _jsx(Container, { children: data }); } var templateObject_1; //# sourceMappingURL=text-viewer.js.map