Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
fetchRecords() {
const { document } = this.props;
const url = document.links.csv;
if (this.state.rows.length < this.state.requestedRow) {
if (this.parser !== null) {
this.parser.resume();
} else {
// set chunk size to 100 KB
Papa.RemoteChunkSize = 1024 * 100;
Papa.parse(url, {
download: true,
delimiter: ',',
newline: '\n',
encoding: 'utf-8',
// header: true,
chunk: (results, parser) => {
this.parser = parser;
this.setState((previousState) => {
const rows = previousState.rows.concat(results.data);
const rowIndex = rows.length;
if (rowIndex > previousState.requestedRow) {
parser.pause();
}
return { rows };
});
fetchCsvData() {
const { entity } = this.props;
const url = entity.links.csv;
// set chunk size to 100 KB
Papa.RemoteChunkSize = 1024 * 100;
Papa.parse(url, {
download: true,
delimiter: ',',
newline: '\n',
encoding: 'utf-8',
chunk: (results, parser) => {
this.setState({
csvHeader: results.data[0],
csvData: results.data.slice(1, 15),
});
parser.abort();
},
});
}
fetchCsvRows() {
const { entity } = this.props;
const url = entity.links.csv;
// set chunk size to 100 KB
Papa.RemoteChunkSize = 1024 * 100;
Papa.parse(url, {
download: true,
delimiter: ',',
newline: '\n',
encoding: 'utf-8',
chunk: (results, parser) => {
this.setState({
csvRows: results.data.slice(0, 10),
});
parser.abort();
},
});
}