0

I'm new to React Native and I'm creating a content-oriented app. I'm trying to do something pretty simple which is: include some static data/resources in my app, which I can read/load in my application. In a desktop application, it would be as simple as installing some local *.csv files, opening and reading them within the application, but I can't find the way to do that in the React Native environment.

From my research it seems people usually create source (.js) files with data in json format, but that would be awkard because my app uses a lot of tables for example, and the .csv representation would be way better.

Is there any way to store read static assets/data which are not json or in .js source files?

Pedro Affonso
  • 1,656
  • 15
  • 26
  • Yes in React Native we usually work with a json file to handle static data. You can try to convert csv to json. There are some good tools out there. – Arbnor Dec 08 '20 at 21:36

1 Answers1

0
  1. Get file path using react-native-fs to get the file path.

  2. install the package papaparse using yarn add papaparse

     import Papa from "papaparse";
    
     Papa.parse(file-path, {
      complete: function(results) {
       console.log(results);
      }
    });
    

If the CSV has headers

    Papa.parse(file-path, {
     header: true
     complete: function(results) {
      console.log(results);
     }
   });

so it will render each item as objects in array form

Ridwan Ajibola
  • 873
  • 11
  • 16