Logo

dev-resources.site

for different kinds of informations.

Read Text Asset File in Expo

Published at
1/14/2025
Categories
expo
reactnative
Author
somidad
Categories
2 categories in total
expo
open
reactnative
open
Author
7 person written this
somidad
open
Read Text Asset File in Expo

§ Install expo-asset and expo-file-system:

npx expo install expo-asset expo-file-system
Enter fullscreen mode Exit fullscreen mode

§ Add expo-asset plugin in app.config.js (or in app.json), if it has not been added by the previous step:

   plugins: [
+    "expo-asset"
   ]
Enter fullscreen mode Exit fullscreen mode

§ Install @expo/metro-config:

npm install --save-dev @expo/metro-config 
Enter fullscreen mode Exit fullscreen mode

§ Create metro.config.js:

 const {  getDefaultConfig } = require("expo/metro-config");

 const config = getDefaultConfig(__dirname);
+config.resolver.assetExts.push("txt");

 module.exports = config;
Enter fullscreen mode Exit fullscreen mode

§ Create or put a text file under /assets folder

§ Code:

async function readTextAsset() {
  try {
    const nodeRequire = require("@/assets/filename.txt");
    const asset = Asset.fromModule(nodeRequire);
    await asset.downloadAsync();
    if (asset.localUri) {
      const fileContents = await readAsStringAsync(asset.localUri);
      // Do something with `fileContents`
    }
  } catch (error) {
    console.error(error);
  }
}
Enter fullscreen mode Exit fullscreen mode
reactnative Article's
30 articles in total
Favicon
Using Direct Line botframework in a React Native Application to connect to Copilot Studio Agent
Favicon
[Video]Build a Full-Stack Mobile App with React Native Expo and Payload CMS in 2025!
Favicon
Introducing EAS Hosting: Simplified deployment for modern React apps
Favicon
Auto Resize multiline TextInput in React Native
Favicon
Read Text Asset File in Expo
Favicon
Flat list horizontal all Items perfectly visible in iOS not in android ContentContainerStyle
Favicon
Building High-Performance React Native Apps[Tips for Developers]
Favicon
React Native With TypeScript: Everything You Need To Know
Favicon
Building the 'One of a Kind' Ultimate Mobile App Framework. Seeking exceptional engineers to join the journey.
Favicon
Ship mobile apps faster with React-Native-Blossom-UI
Favicon
Encryption in React Native apps enhances data security, protecting user information and ensuring privacy. However, it also presents challenges, such as performance overhead and complex implementation
Favicon
How to Integrate Stack, Bottom Tab, and Drawer Navigator in React Native
Favicon
🌎 Seamless Multi-Language Support in React Native
Favicon
Mastering React Native with TypeScript: From Basics to Brilliance - Part 1
Favicon
Building "Where Am I?": A GeoGuessr Alternative for Mobile
Favicon
React Native is powerful modern technology
Favicon
How to Build a Centered Input Field for Amounts in React Native
Favicon
Compound Component pattern in react
Favicon
Pop Quiz: Is There a Bug in This React Native Component?
Favicon
The Unlikely Fix: How a Simple Folder Change Saved My React Native Journey
Favicon
How to Integrate Stack and Bottom Tab Navigator in React Native
Favicon
How to make a view expand downwards in an inverted FlatList?
Favicon
Building a Custom Star Rating Component in React Native with Sliding and Press Interactions
Favicon
Choosing the Right Compiler for React Native Development in 2025
Favicon
Simple remove transition animation in react native
Favicon
How to Hire Dedicated React Native Developers for Customizable Features
Favicon
React Native’s New Architecture: Sync and async rendering
Favicon
Top Mobile App Development Company in Bangalore | Hyena IT
Favicon
Mastering Import Order in React: A Deep Dive Into Best Practices and Tools
Favicon
Creating Custom Inputs for Regex Validation in React and React Native

Featured ones: