Reputation: 361
I have a html page stored remotely, How can I access using Reactjs ? if I can able to access then how I can parse that page and render in browser ? can any one faced this kind of challenge, please let me know the solutions if you found.
Thank you.
Upvotes: 0
Views: 1068
Reputation: 781
Fetching can be done with fetch("http://example.com/path/to/file.html")
- this returns a Promise.
If you want to use the fetched html page inside of react, you can fetch it, save it in the state and then render it using the dangerouslySetInnerHTML
property on a div - check out this codesandbox example.
Upvotes: 0
Reputation: 61
You can use the fetch API to download and render the page.
fetch("http://www.example.com/home.html")
.then((response) => response.text())
.then((html) => { document.getElementById("content").innerHTML = html; })
.catch((error) => { console.warn(error); });
Upvotes: 1