Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing Text from local json file in React native

Tags:

react-native

I am wondering how the common way is to import a huge text to a View. In my case i am developing a React Native App for Android and iOS, and on one of my Views i want to present the "Terms of Use" document. Now when i just import/copy paste it into a Text Component it just can´t be the right solution, especially when i need to use localization to present the needed language. How would i "import" this Text-Block so it is nice formatted and i don´t need to put everything into my View:

 <View style={styles.container}>
      <Text style={styles.text}> |JSON - Text-file, with about 600 words -> Terms of Use document |</Text>
 </View>
like image 878
BigPun86 Avatar asked Oct 12 '15 15:10

BigPun86


People also ask

How do I import a local JSON file into react native?

To fetch data from local JSON file with React Native, we can import the JSON file with import . import * as React from 'react'; import { View, Text } from 'react-native'; import { Card } from 'react-native-paper'; import customData from './customData. json'; const App = () => { return ( <View> <Text>{JSON.

Can we import JSON file in react?

Importing JSON file in create-react-appcreate-react-app supports importing JSON files right out-of-the-box. For example, you can import a JSON file in the following way: import products from '../path/to/products.


1 Answers

You can use:

import file from './config/TermsAndCondition.json';

then you can treat it as a javascript object:

file.description
like image 189
Damathryx Avatar answered Sep 28 '22 01:09

Damathryx