export-data
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -27,3 +27,2 @@ "use strict"; | ||
const react_1 = __importStar(require("react")); | ||
const react_dom_1 = require("react-dom"); | ||
const utils_1 = require("../utils"); | ||
@@ -35,14 +34,16 @@ const FileDownloadLink = ({ fileType, encoding = "utf-8", filename = "data", columnNames, rows, onClick, setsDataAsyncInOnClick, children, }) => { | ||
(0, react_1.useEffect)(() => { | ||
setDownloadUrl((0, utils_1.createDownloadUrl)((0, utils_1.dataToString)(columnNames, rows, fileType), fileType, encoding)); | ||
}, [columnNames, rows, fileType, encoding]); | ||
(0, react_1.useEffect)(() => { | ||
var _a; | ||
const data = (0, utils_1.dataToString)(columnNames, rows, fileType); | ||
if (downloadOnDataChange) { | ||
(0, react_dom_1.flushSync)(() => setDownloadUrl((0, utils_1.createDownloadUrl)(data, fileType, encoding))); | ||
(_a = downloadLink.current) === null || _a === void 0 ? void 0 : _a.click(); | ||
setDownloadOnDataChange(false); | ||
(_a = downloadLink.current) === null || _a === void 0 ? void 0 : _a.click(); | ||
} | ||
else { | ||
setDownloadUrl((0, utils_1.createDownloadUrl)(data, fileType, encoding)); | ||
}, [downloadUrl]); | ||
const handleClick = (e) => { | ||
/* The data url is already set, so this click is only to trigger the download */ | ||
if (downloadOnDataChange) { | ||
return; | ||
} | ||
}, [columnNames, rows, fileType, encoding]); | ||
const handleClick = (e) => { | ||
if (onClick) { | ||
@@ -49,0 +50,0 @@ onClick(e); |
{ | ||
"name": "export-data", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Export data in React to CSV and other file formats", | ||
@@ -5,0 +5,0 @@ "types": "./lib/cjs/types/index.d.ts", |
Sorry, the diff of this file is not supported yet
157
11801