0

I'm trying to return a piece of html code in a react function. However, rather than copying the file I want and put it the concerned code in quotes, I would like to do something like :

my_func() {
   return doc.documentElement.innerHTML;
}

Where doc would be a reference to some other file like :

./path/myfile.html

Is there any method that allows me to do that? Or am I constrained to copy all the code in my file.html and put it in quotes in my return function?

Thanks

Dime
  • 41
  • 6
  • Does this answer your question? [How do I load the contents of a text file into a javascript variable?](https://stackoverflow.com/questions/196498/how-do-i-load-the-contents-of-a-text-file-into-a-javascript-variable) – Heretic Monkey Mar 23 '20 at 23:00

1 Answers1

0

You can use jQuery.get for example, to get your file and parse the content :

$.get('./path/myfile.html').done(function(data){
    console.log(data);
});

https://api.jquery.com/jQuery.get/