I'm doing a react project using create-react-app and my current goal is to load an external js file (that is hosted in iis) and use their data.
I'm getting this file throught a script in index.html like:
<script type="text/javascript" src="http://localhost:5000/GetJsFile"></script>
Example of my js file:
var data = {
vars: {
id: ****,
user ******,
name: *******,
date: *******,
}
//...
}
My question is: how can I use/access the data from js file inside a component of react js?
jsonbutjavascript. Either export / import your js Object or call a json by an online API. Loading json files from your local file system will not work in a browser context but in node. You cannot simply add a script tag and make the src a json file...window.datato access it.importorrequire. Often this is also used to import libraries and stuff out offnode_modulesdataor aboutlogic / functionality? Data will be called usinghttp requestswhile third-party-functionality will be imported usingnpm. If your script is not available via npm you can still push it into a git repository and include it using npm