Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6581

React Native Expo: Read local file from assets folder

$
0
0

I am trying to read a local CSV file that is in my projects assets folder (and not on the FS of the test device).

HomeScreen.tsx:

useEffect(() => {    Papa.parse(require('../assets/wienerlinien.csv'), {        delimiter: ';',        header: true,        newline: "\r\n",        complete: (result) => {            console.log(result);            // this just prints {data: Array(0), errors: Array(0), meta: {…}} 

This code prints an empty object on Web and on Android I get a Unable to resolve "../assets/wienerlinien.csv" from "screens\HomeScreen.tsx".

This confuses me because React Native was perfectly capable of finding and displaying a local image from the same folder like this:

<Image source={require('../assets/profile.jpg')} style={styles.profileImage}/>

How do I access and parse my CSV file from the assets folder?

In case it matters the CSV looks like this (assets/wienerlinien.csv):

"HALTESTELLEN_ID";"TYP";"DIVA";"NAME";"GEMEINDE";"GEMEINDE_ID";"WGS84_LAT";"WGS84_LON";"STAND"214460106;"stop";60200001;"Schrankenberggasse";"Wien";90001;48.1738010728644;16.3898072745249;""214460107;"stop";60200002;"Achengasse";"Wien";90001;48.2845258075837;16.4488984539143;""

Viewing all articles
Browse latest Browse all 6581

Latest Images

Trending Articles



Latest Images