/    Sign up×
Community /Pin to ProfileBookmark

How to call a function within render()

Hi all. I’m kinda new to js so thank you in advance for your help.

I have a bit of function like this:

render() {
return (
<div className=”Account>
</div>
);
}

I would like to add a function within the div but when I put the function in it just prints the code as text.
render() {
return (
<div className=”Account>
printBalance();
</div>
);
}

printBalance() {
return “Your balance is…”;
}

How do I differentiate the tags and code in this case? I’m not even sure why the raw html works well in that render. Can anyone enlighten me as to how best (practice) accomplish what I need?

Thanks
bluprint

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@SempervivumMay 21.2018 — In your initial code:

1. the quotes for the string are missing

2. the double quotes for the class name are missing

3. there is no tag "className", obviously you intend to set the class

This is correct:
return ('&lt;div class="Account"&gt;&lt;/div&gt;');

How do I differentiate the tags and code in this case?[/quote]
You need to enclose the strings or tags in quotes and contatenate them with the function (or variables) by "+":
return ('&lt;div class="Account"&gt;' + printBalance() + '&lt;/div&gt;');
Copy linkTweet thisAlerts:
@chauchilam2102May 21.2018 — THANK YOU
Copy linkTweet thisAlerts:
@bluprintauthorMay 21.2018 — Thank you so much!
Copy linkTweet thisAlerts:
@bluprintauthorMay 21.2018 — For posterity, I will add that the earlier mentioned "raw html" was working because it turns out it is jsx in the context of React. I also just now learned about jsx. ? Thanks again.
×

Success!

Help @bluprint spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...