How to call a method inside a react material-ui components
<p>i'm implementing a chat system with a functionality of adding emojis. for that i've created a function that returns a component along with the text and image.</p>

<p>the function ive used</p>

<pre><code> test: function(item1) {
    var texts = item1.message.split(/:\)/g);
    console.log(texts);
    var content = [];
    for(var i = 0; i &lt; texts.length - 1; i++) {
        content.push(texts[i]);
      content.push(&lt;img src={Emojis[0].uri}/&gt;);
    }
    return content.map(function(emoji) {
      return (&lt;span&gt; {emoji} &lt;/span&gt;)
    })
  },
</code></pre>

<p>for this chat i'm using socketio and node express. and the message returned is displayed on a react component. the "threads" jason contains the all received messages (keys inside threads are message,user1). now what i want is to call the above test function inside secondaryText and pass the {item.message} as parameter. but when ever it runs it says "Uncaught ReferenceError: test is not defined". </p>

<pre><code>  &lt;div&gt;
      {

        this.state.threads.map(function(item) {

            return (&lt;ListItem
                leftAvatar={&lt;Avatar src="profile pic" /&gt;}
                primaryText={item.user1}
                secondaryText={test({item})}
                secondaryTextLines={2}
            /&gt;
            );

        })
      }
        &lt;/div&gt;
</code></pre>

<p>the whole react component</p>

<pre><code>    const Threads = React.createClass({

  getInitialState: function() {
    return {
        threads: ThreadStore.getmessages()
    }
  },

  userlistio:function(){
      console.log(" awooooo");
    socket.on('chatList',function(data){
        console.log(data.Userlist+" awa!");
    }.bind(this));
 },

    componentDidMount: function () {
        ThreadStore.addChangeListener(this._onChange);

    },
    _onChange: function () {
        this.setState({
            threads: ThreadStore.getmessages()
        });

    },
  socketio: function() {

    socket.on('chat', function (data) {
      console.log(data.message);
        console.log(data.user2);
      this.setState({threads: data.message});
    }.bind(this));
  },
  _sendmessage: function() {
      let message = this.refs.message2.value;
      let User2 = this.refs.message1.value;
      let Eml = LoginStore.getEmail();
    let chat = {
        message: message,
        user1: User1,
        user2: User2,
        emailusr1: Eml
    }
    console.log('Emiting ...');
    socket.emit('message', chat);
    console.log('Done ...');

  },
  test: function(item1) {
    var item = {
        message: ':) hello :) hello :) hello :)'
    }
    console.log("smilies working");
    var texts = item1.message.split(/:\)/g);
    console.log(texts);
    var content = [];
    for(var i = 0; i &lt; texts.length - 1; i++) {
        content.push(texts[i]);
      content.push(&lt;img src={Emojis[0].uri}/&gt;);
    }
    return content.map(function(emoji) {
      return (&lt;span&gt; {emoji} &lt;/span&gt;)
    })
  },
  render: function() {
    return (
      &lt;Paper zDepth={1} style={Sty1}&gt;
        {this.userlistio()}
        {this.socketio()}
        &lt;CardTitle title="Threads" subtitle="" /&gt;
        &lt;CardText&gt;
          Message threads
            &lt;div&gt;
          {

            this.state.threads.map(function(item) {

                return (&lt;ListItem
                    leftAvatar={&lt;Avatar src="profile pic" /&gt;}
                    primaryText={item.user1}
                    secondaryText={test({item})}
                    secondaryTextLines={2}
                /&gt;
                );

            })
          }
            &lt;/div&gt;
            &lt;Paper style={Sty2} &gt;
                &lt;input type="text" ref="message1" /&gt;
                &lt;input type="text" ref="message2" /&gt;
          &lt;input type="button" onClick={this._sendmessage} value="Send message" /&gt;
            &lt;/Paper&gt;



        &lt;/CardText&gt;
        &lt;CardActions&gt;

        &lt;/CardActions&gt;
        &lt;/Paper&gt;
    );
  }

});
</code></pre>