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

1.5K
Views
React Native: nodo de texto inesperado: . Un nodo de texto no puede ser hijo de una <Vista>

Estoy trabajando para hacer una aplicación React Native y recibo el error:

Nodo de texto inesperado: . Un nodo de texto no puede ser hijo de una <Vista>.

No puedo averiguar a qué nodo de texto se refiere este error. Mi objetivo es representar una variedad de vistas.

Aquí hay un fragmento de código mínimo que reproduce el error:

 import React from 'react'; import { StyleSheet, Text, View } from 'react-native'; function fun() { const views = []; const style = {backgroundColor: 'red', height: 100, width: 100}; for (let i=0; i<3; i++) { views.push( <View key={i} style={style}/> ) } return views; } export default function App() { return ( <View style={styles.container}> <Text>Open up App.js to start working on your app!</Text> <View> {fun()} </View> </View> ); } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#fff', alignItems: 'center', justifyContent: 'center', }, });
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

El problema es que una función que se supone que es un componente JSX, o en este caso devolver un componente JSX, debe ser un elemento JSX único y no una matriz de elementos JSX.

Por lo tanto, debe agregar un componente de nivel superior que podría ser solo un fragmento.

 function fun() { const views = [] const style = { backgroundColor: "red", height: 100, width: 100 } for (let index = 0; index < 3; index++) { views.push(<View key={index} style={style} />) } return <>{views}</> }
about 4 years ago · Juan Pablo Isaza Report

0

Está devolviendo una serie de vistas. Debe devolver vistas como los niños. Prueba algo como:

 function fun() { const style = { backgroundColor: "red", height: 100, width: 100 }; return [0, 1, 2].map(() => <View key={i} style={style} />); } export default function App() { return ( <View style={styles.container}> <Text>Open up App.js to start working on your app!</Text> <View> {fun()} </View> </View> ); } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#fff', alignItems: 'center', justifyContent: 'center', }, });
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!