Created
May 14, 2020 05:26
-
-
Save borispoehland/7e6d771721778e78341b37223a48842f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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