Skip to content

Instantly share code, notes, and snippets.

@makarovas
Created July 17, 2018 11:08
Show Gist options
  • Save makarovas/4191b8e46704ae36efa07624e47bb265 to your computer and use it in GitHub Desktop.
Save makarovas/4191b8e46704ae36efa07624e47bb265 to your computer and use it in GitHub Desktop.
var jsonData = require('../../file.json');
class blah extends React.Component {
render(){
var data;
function loadJSON(jsonfile, callback) {
var jsonObj = new XMLHttpRequest();
jsonObj.overrideMimeType("application/json");
jsonObj.open('GET', "../../file.json", true);
jsonObj.onreadystatechange = function () {
if (jsonObj.readyState == 4 && jsonObj.status == "200") {
callback(jsonObj.responseText);
}
};
jsonObj.send(null);
}
function load() {
loadJSON(jsonData, function(response) {
data = JSON.parse(response);
console.log(data);
});
}
load();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment