Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

245
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda