Problem with adding external link to my React App

I’m working with React on VS Code after loading the template with

npx create-react-app app

I’m trying to add a CDN Marked 2.1.3 and FCC testability library

but I don’t know where to put it. Normally with regular html, css, JavaScript I would do

<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/2.1.3/marked.js"  referrerpolicy="no-referrer"></script>

and

<script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>

to the head or body tag

But with React, it doesn’t work when added

i found this solution
How To Use CDN Link In React

it seem to work for the person here

this is my code


Hi @St_pardon !

Did you try moving it to the body?
Does it work there?

Yeah, if it depends on the app being there (which as it’s the test bundle, I assume yes, that’s going to be important) then it won’t work because the script is before any of the HTML (and the HTML rendered by the app). There’s nothing there when the script runs, so it’s not going to be able to do anything (EDIT: open the console and look for errors that refer to something being null that the script is trying to access, that’s normally the clue). So either put it at bottom, just before the closing body tag, or add defer to it so that it won’t run until the DOM is ready – <script src="path/to/test/stuff" defer></script> (see Scripts: async, defer for an overview of why you use this).

1 Like

Yes I did, it still didn’t work

Thank you, this worked

but there is something else, how can i add a online CDN to react so i can reference the methods in my app.
i’m trying to use the Renderer method from this CDN markedown library

i’m suppose to use it on my app like this
const convert = new marked.Renderer(); renderer.link = function (href, title, text) { return ${text}; };

how can i add the link to my app

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.