annaoomph
annaoomph

Reputation: 572

React-native require any file

Can I use require(...) in React-Native to import any file, for example file.txt or a file with any other extension? How can I do it?

Upvotes: 1

Views: 1127

Answers (1)

Vivek Verma
Vivek Verma

Reputation: 551

Yes you can use require to import any kind of file. As per ES6 import/export is preferred over require. This link might help you understand it better : Using Node.js require vs. ES6 import/export

Edit:

Actually for using text file you have keep text in a .json file in object format. Simple text files cannot be imported.

For example text.json content:

   {
       'first_name': 'Vivek',
       'last_name': 'Verma'
   }

and then you can import it like

   import Text from 'path/to/text.json';

and use it like

   Text.first_name
   Text.last_name

Upvotes: 1

Related Questions