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?
Asked
Active
Viewed 960 times
1
1 Answers
1
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

Vivek Verma
- 501
- 4
- 7
-
I wonder how I would do it using import? What the syntax would be? – annaoomph Jun 20 '18 at 09:40
-
Right now I get `Unable to resolve module './labels.txt' from '...\index.android.js': could not resolve '...\labels.txt' as a file nor as a folder` while making a bundle – annaoomph Jun 20 '18 at 09:40