【发布时间】:2020-08-03 18:22:57
【问题描述】:
我有一个项目 A(见下文),我使用“yarn build”构建这个项目并生成 main.js 文件。我想将此 main.js 文件用作另一个反应项目 B 的依赖项。(我关注:React components and module exports)但它不起作用。这是正确的方法吗?您能提供一些建议吗?
项目A:
index.tsx
import { Home } from "./view/Home";
module.exports ={
Home: Home
}
home.tsx
import * as React from "react";
import "../css/view/Home.css";
import { Background } from "../component/Background";
import { CL } from "../component/C";
import { DL } from "../component/D";
type Props = {
P: number;
Q: Array<string>;
R: number;
S: number;
T: number;
U: number;
}
export class Home extends React.Component<Props, any> {
render() {
return (
<div className="home">
<Background P={this.props.P}
Q={this.props.Q}/>
<CL R={this.props.R}
S={this.props.S}/>
<DL T={this.props.T}
U={this.props.U}/>
</div>
);
}
}
项目 B
import React from "react";
import './App.css';
import imagesPath from "./data/imagesPath.json";
var Home = require('./main.js').Home;
const transitionSettings = {
P: 8000,
Q: imagesPath,
R: 55,
S: 28,
T: 5000,
U: 23
}
function App() {
return (
<Home {...transitionSettings} />
);
}
export default App;
【问题讨论】:
标签: javascript reactjs typescript frontend