Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

242
Views
When i export my array, i can only list the last item of my array - React Native

Currently i'm making a word test application. I found a database and added all items in my array.

Here is my code:

import React from 'react';
import Navigator from './routes/menuStack';

export const N5Words = [];

export default function App(){

  var RNFS = require('react-native-fs');

  RNFS.readFileAssets('N5.txt', 'utf8')
  .then((contents) => {

    let allWords = contents.split('\n');
    let word = { key: 0, japanese: 'japanese', kana: 'kana', turkish: 'turkish' }

    for (var i = 0; i < allWords.length; i++){

      let splittedRow = allWords[i].split('\t');

      word.key = i;
      word.japanese = splittedRow[0].toString();
      word.kana = splittedRow[1].toString();
      word.turkish = splittedRow[2].toString();

      N5Words.push(word);

    }

  })
  
  return(
    <Navigator/>
  );
}

I want to use this array in another scripts. So, i write the code below, on the other script:

import React from 'react';
import {StyleSheet, View, Text, Button, ScrollView} from 'react-native';
import { globalStyles } from '../styles/global';
import { N5Words } from '../App';

export default function KelimeTesti({ navigation }){

    return (
        <View style={globalStyles.container}>

        <Text style={globalStyles.smallText}>You're in Kelime Testi</Text>
        
        <ScrollView>
        { N5Words.map((word) => {
            return (
                <View key={word.key}>
                    <Text style={globalStyles.smallText}>{word.japanese}</Text>
                </View>
            )
        })}
        </ScrollView>

        </View>
    )
}

But it's not working. When i export the array and use that array in another script, only the last item of my script is listed.

Output of the Code

There is no problem with the first code. I checked the items in console and it's reading all the words properly and they have unique id's which is from 0 to 668.

I get this error 668 times (for every word):

Error Image

And that's how my database looks like :

会う  あう  to meet
青   あお  blue
青い  あおい blue
赤   あか  red
赤い  あかい red
明い  あかるい    bright
秋   あき  autumn
開く  あく  to open,to become open
開ける あける to open
上げる あげる to give
朝   あさ  morning
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I solved the problem. I'm writing this for anyone who deals with this problem. Instead exporting and importing the database array, i sent it with navigation parameter. And i get the array with getParam method. Then it worked.

While listing the array, i used both map() function and flat list. I wasn't able to list the items because i was getting an error which is "undefined is not an object". I also solved that problem. I was using a variable called "word" as in my question. I changed it into "item" and that's it. I think we can't use another variable name except "item" while listing array.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!