I know that in Node.js, when you require some file with variables or functions, from the second time it is loaded from the memory.
This concept is the same in import in React.js?
Can I load multiple variables or functions using import, and it will load from the memory the second time?
-
2check this out - stackoverflow.com/questions/31354559/…Monica Acha– Monica Acha2019-02-09 14:07:36 +00:00Commented Feb 9, 2019 at 14:07
-
Its good to know, but where is the answer for my question there?Or Assayag– Or Assayag2019-02-09 14:12:10 +00:00Commented Feb 9, 2019 at 14:12
1 Answer
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.
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.
Can i load multiply variables or functions using import, and it will load from the memory in the second time?
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.