Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

248
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda