简体   繁体   English

反应原生 | 导入文件性能

[英]React Native | import file performance

There are multiple ways to import a file for React native.有多种方法可以为 React Native 导入文件。

  1. Direct import.直接进口。
  2. First to export and then import.先导出再导入。
//1
import BackButton from '../components/BackButton'

//2
import {BackButton} from '../components'

//components -> index.js
import BackButton from '../BackButton'

export {
BackButton
}

I was wondering is there any difference in performance between these two?我想知道这两者之间的性能有什么不同吗? Is it a factor that affects the rendering time, even if only a little.是不是影响渲染时间的一个因素,哪怕只有一点点。

Import the component from another file like从另一个文件导入组件,如

import BackButton from '../components/BackButton'

or you could also use component indexing for better import like "components/index.js"或者您也可以使用组件索引来更好地导入,例如“components/index.js”

import BackButton from "./BackButton";
import Loader from "./Loader";
import Text from "./Text";

export {
  Loader,
  ButtonView,
  Text
};

Usage like用法像

import {BackButton} from '../components'

It does not affect the performance but component indexing is a better approach to implement when you have multiple files in the component它不会影响性能,但是当组件中有多个文件时,组件索引是更好的实现方法

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

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