Can't get .map () working in React Native render ()

How can I make this work, {showExamples} does not show any output. Full source code here: https://rnplay.org/apps/t2E4Ig

var MyApp = React.createClass({
  render() {
    var showExamples = examples.map(function(value){
                return (
            <View>
                {value.render}
            </View>
          );
            });

    return (
        <View>

        <Image
          source={{uri: 'http://facebook.imtqy.com/react/img/logo_og.png'}}
          style={styles.base}
        />

        {showExamples}

        </View>
    );
  }
});
+4
source share
2 answers

The property renderfor each of the elements in the example is a function, so you need to call it with {value.render()}instead of trying to visualize the function: with {value.render}.

+3
source

you can try this.

var MyApp = React.createClass({
  render() {

   return (
    <View>

      <Image
        source={{uri: 'http://facebook.imtqy.com/react/img/logo_og.png'}}
      style={styles.base}
      />

     {
       examples.map(function(value, i){
            return (
              <View key={i}>
                {value.render}
             </View>
           );
        })
     }

    </View>
);

}});

+2
source

Source: https://habr.com/ru/post/1614387/


All Articles