Ask Your Question
4

What is the method to utilize React.js from a different .js file through a CDN link in the same way as regular JavaScript or Vue.js?

asked 2021-10-21 11:00:00 +0000

david gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2022-08-06 17:00:00 +0000

lalupa gravatar image

To use React.js from a CDN link, follow the below steps:

  1. Retrieve a CDN link for React.js from a reputable source or from the official React.js documentation.
  2. Create a new HTML file or open an existing HTML file from your project in a text editor.
  3. Add the CDN link to the <head> section of the HTML file using the following code:
<head> 
   <script src="https://cdn.jsdelivr.net/npm/react@17.0.2/umd/react.development.min.js"></script> 
   <script src="https://cdn.jsdelivr.net/npm/react-dom@17.0.2/umd/react-dom.development.min.js"></script> 
</head> 
  1. Create a separate JavaScript file that will contain your React.js code. You can use the .js file extension.
  2. In the JavaScript file, use the following code to render your React.js component:
const element = React.createElement("h1", null, "Hello, world!");
ReactDOM.render(element, document.getElementById("root"));
  1. Add the JavaScript file to the <body> section of the HTML file using the following code:
<body> 
   <div id="root"></div> 
   <script src="example.js"></script> 
</body> 
  1. Open the HTML file in a web browser to view your React.js component.

By following the above steps, you can utilize React.js from a different .js file through a CDN link just like regular JavaScript or Vue.js.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-10-21 11:00:00 +0000

Seen: 12 times

Last updated: Aug 06 '22