Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
338 views
in Technique[技术] by (71.8m points)

javascript - Why does the following code show nothing?

I am trying to learn react-native and is stuck at this point. The following code do not display anything, however if I move the content of the renderArticles inside the return method of the App function, it seems to work again.

import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';


const ARTICLES = [
  { id: '1', uri: require('./assets/1.jpg')},
  { id: '2', uri: require('./assets/2.jpg')},
  { id: '3', uri: require('./assets/3.jpg')},
  { id: '4', uri: require('./assets/4.jpg')},
  { id: '5', uri: require('./assets/5.jpg')},
];

export default function App() {
  const renderArticles = () => {

    ARTICLES.map( (item) => {
      return (
        <View>
          <Text>Lorem Ipsum</Text>
        </View>
      );
    })
}

  return (
    <View style={styles.container}>
     {renderArticles}
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

What am I missing here?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...