0

I'm trying to run a simple React component and not sure why this isn't working.

For some reason, addRows isn't running. Can someone explain why?

var CreateRows = React.createClass({
    addRows : function(){
        return (
                <tr>
                    <td>Morgan</td>
                    <td>[email protected]</td>
                </tr>

            )
    },

    render: function(){
        return (
            <tbody>
                {this.addRows}
            </tbody>
        )
    }
});
2
  • Invoke the method - {this.addRows()} Commented Nov 16, 2016 at 12:39
  • thank you. I've been following this tutorial - tylermcginnis.com/… They don't use () to invoke functions in it, but yet it works. Can you explain why? Commented Nov 16, 2016 at 12:43

1 Answer 1

2

You have to call the function with { this.addRows() }. With your code you are only referring to the function but not invoking it. Such a statement could be used for defining a function e.g. like onClick={ this.addRows }

Sign up to request clarification or add additional context in comments.

2 Comments

ahh, that explains why question to the comment! thank you.
Great :) Please accept my answer as correct in that case ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.