Node.js需要vs React.js导入 [英] Node.js require vs React.js import

查看:102
本文介绍了Node.js需要vs React.js导入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在Node.js中,当您需要一些带有变量或函数的文件时,是从第二次从内存中加载文件.
这个概念与React.js中的import相同吗?
我可以使用import加载乘法变量或函数,并且第二次从内存中加载吗?

I know that in Node.js, when you require some file with variables or functions, from the second time it loaded from the memory.
This concept is the same in import in React.js?
Can i load multiply variables or functions using import, and it will load from the memory in the second time?

推荐答案

反应是UI库.它与import关键字无关.任何可用的JavaScript功能都可以与React一起使用,包括import-或require(如果可用).

React is UI library. It isn't related to import keyword. Any available JavaScript features can be used together with React, including import - or require, if it's available.

问题是关于ES vs CommonJS模块.前者是通用的,后者主要在Node中使用,但也由Webpack和其他捆绑程序支持,因此importrequire都可以在React应用程序中使用.

The question is about ES vs CommonJS modules. The former are universal, the latter are primarily used in Node but also suppored by Webpack and other bundlers, so both import and require can potentially be used in React application.

我可以使用import加载乘法变量或函数,第二次从内存加载吗?

Can i load multiply variables or functions using import, and it will load from the memory in the second time?

这描述了特定于所有JavaScript模块(包括ESM import)的缓存行为.对模块进行一次评估,导出将被缓存,并可以在后续导入中使用.

This describes caching behaviour that is specific to all JavaScript modules, including ESM import. A module is evaluated once, the export is cached and can be used on subsequent import.

这篇关于Node.js需要vs React.js导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆