简体   繁体   English

仅在大型反应项目中渲染特定组件

[英]Only render specific component in a big react project

In my React project which the file structure like below:在我的 React 项目中,文件结构如下:

| | src --- index.js --- | src --- index.js --- | first --- |第一--- | --- first.jsx --- | --- first.jsx --- | second --- |第二个--- | --- second.jsx --- 第二个.jsx

When 'npm start' the React project it will start from the index.js and render the first.jsx and second.当'npm start' React 项目时,它将从 index.js 开始并渲染 first.jsx 和 second。 jsx. jsx。 But How can I only show second.jsx Component.但是我怎样才能只显示 second.jsx 组件。

Maybe this sounds very simple, however if you really in a big React project with billions of lines of code, I guess that is not easy.也许这听起来很简单,但是如果你真的在一个有数十亿行代码的大型 React 项目中,我想这并不容易。

Try dynamic import :尝试动态导入

Before:前:

import { add } from './math';

console.log(add(16, 26));

After:后:

import("./math").then(math => {
  console.log(math.add(16, 26));
});

That way you can dynamically load only those files that are needed.这样您就可以只动态加载那些需要的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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