Calling a function in the render function
jannavarro opened this issue · comments
jannavarro commented
So I have the omniscient component below. problem is the displayMessageIfError function does not appear to get written to the DOM. I also tried variations such as { displayMessageIfError} or {displayMessageIfError()} or {this.displayMessageIfError()}
component(function () {
function displayMessageIfError(){
return <div><p>Bad login information</p></div>;
}
return (
<div>
<form onSubmit={this.handleSubmit}>
//some rendering here
{displayMessageIfError}
</form>
</div>
}
Alberto Leal commented
Code seems invalid.
This is my interpretation and should work:
component(function () {
function displayMessageIfError(){
return <div><p>Bad login information</p></div>;
}
return (
<div>
<form onSubmit={this.handleSubmit}>
//some rendering here
{displayMessageIfError()}
</form>
</div>
);
});
jannavarro commented
@dashed you are correct. That did work. I thought I did try that, probably I may have some typographical errors earlier. Thanks!