I am here with a well-known problem related to external script loading inside react application. Despite many articles on the web and a lot of similar questions asked in StackOverflow, I can't solve my problem.
I am trying to integrate Yodlee Fastlink into my app. This is the script which I should run.
((window) => {
document.getElementById('btn-fastlink').addEventListener(
'click',
(event) => {
window.fastlink.open({
fastLinkURL: 'fastlinkURL',
accessToken: 'Bearer accessToken',
params: {
configName: 'Aggregation',
},
}, 'container-fastlink');
},
false,
);
})(window);
And here is the react component.
import React, { useEffect } from 'react';
import { Button } from 'react-bootstrap';
export const LinkBankDetails = React.memo((props) => {
useEffect(() => {
const script = document.createElement('script');
script.src = '/public/external-services/fastlink-integration.js';
script.defer = true;
script.type = 'text/javascript';
document.body.appendChild(script);
}, []);
return (
<div id="container-fastlink">
<Button type="submit" id="btn-fastlink">Continue</Button>
</div>
);
});
And in the end, I get this error
Uncaught SyntaxError: Unexpected token '<'
I have been struggling almost 2 hours and need your help.
<LinkBankDetails>mounts.You need to enable JavaScript to run this app., then you are serving your HTML file, and not your script as you expect. Look at the documentation on how to serve static files. If that doesn't help, tell us your configuration details (Webpack, if you're using Create React App, etc.) and then we may have a shot at helping you${process.env.PUBLIC_URL}/external-services/fastlink-integration.jssolved the problem.You can write a response in order to make it accepted.