相关疑难解决方法(0)

如何使用 React 组件作为旧版 HTML/JS 应用程序的一部分?

我有一个使用 HTML/JS 运行的旧 Web 应用程序。我创建了一个新的 React 应用程序,我的目标是开始使用 React 开发新功能/页面,并在当前应用程序中实现它们。

主要目标是在react之外使用React组件,例如:

<html>
<head>
<title> My old web applciation</title>
// Imports for my react app / components
</head>
<body>

<!-- Old staff -->

<Footer someProp="1"/>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

到目前为止我所拥有的:

  • 对于全页功能,我使用了 Iframe(并在 React 中为其创建了一条路由)

  • 使用元素 ID,例如::

并在反应中:

const GiveItem = ({ ...props }) => {

  console.log("init give item component");

  return (
    <section>
     Give Item
    </section>
  );
};

try {
  const domContainer = document.querySelector('#giveItem');
  render(e(GiveItem), domContainer);
} catch (e) {
  console.error('Failed to render give item', …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs

4
推荐指数
1
解决办法
3269
查看次数

标签 统计

javascript ×1

reactjs ×1