Skip to content

Instantly share code, notes, and snippets.

@borispoehland
Created May 14, 2020 05:26
Show Gist options
  • Save borispoehland/7e6d771721778e78341b37223a48842f to your computer and use it in GitHub Desktop.
Save borispoehland/7e6d771721778e78341b37223a48842f to your computer and use it in GitHub Desktop.
fetchCsv() {
var rawFile = new XMLHttpRequest();
rawFile.open("GET", require("path/to/local/file.txt"), false);
rawFile.onreadystatechange = () => {
if (rawFile.readyState === 4) {
if (rawFile.status === 200 || rawFile.status === 0) {
var allText = rawFile.responseText;
Papa.parse(allText, {
complete: this.setData, // in this case, set the text as react state
skipEmptyLines: true
});
}
}
};
rawFile.send(null);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment