简体   繁体   中英

Is there any way to link from a React project to a vanilla JS one?

Long story short, when I started learning JS I made a site for someone that didn't upload it online. Now, as I'm learning React, I bought a domain to make a portfolio with personal projects.

What I wanted to do is on the home page of my portfolio have like a few links to different projects. I was wondering if I could do something to somehow navigate to the vanilla JS project (which is not online, but stored locally on my computer) without having to rewrite it in React, as I'm still a beginner and that would take me some time

(Don't know if this is relevant or not but the vanilla JS site has multiple html and js files)

React application is injected into any HTML element with react-dom package.

So given any vanilla project and a valid HTML, you just need to add an entry point like <div id="myReactApplication"></div>

<html lang="en">
  ...

  <body>
    <div>My vanilla application</div>
    <div id="myReactApplication"></div>
  </body>
</html>

And render the root of React application using ReactDOM.render :

import React from "react";
import ReactDOM from "react-dom";

const App = () => {
  return <>React Appliaction</>;
};

ReactDOM.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>,
  document.getElementById("myReactApplication")
);

编辑 solitary-meadow-4e77k

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM